Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Classes/Fluid/ComponentView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace SMS\FluidComponents\Fluid;

use TYPO3Fluid\Fluid\Core\Parser\ParsedTemplateInterface;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\View\AbstractTemplateView;

class ComponentView extends AbstractTemplateView
{
protected ParsedTemplateInterface $parsedTemplate;

public function __construct(
ParsedTemplateInterface $parsedTemplate,
RenderingContextInterface $context,
)
{
parent::__construct($context);
$this->parsedTemplate = $parsedTemplate;
}

/**
* @return ParsedTemplateInterface
*/
protected function getCurrentParsedTemplate()
{
return $this->parsedTemplate;
}
}
8 changes: 7 additions & 1 deletion Classes/Fluid/ViewHelper/ComponentRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Psr\Http\Message\ServerRequestInterface;
use SMS\FluidComponents\Domain\Model\RequiredSlotPlaceholder;
use SMS\FluidComponents\Domain\Model\Slot;
use SMS\FluidComponents\Fluid\ComponentView;
use SMS\FluidComponents\Interfaces\ComponentAware;
use SMS\FluidComponents\Interfaces\EscapedParameter;
use SMS\FluidComponents\Interfaces\RenderingContextAware;
Expand Down Expand Up @@ -142,7 +143,6 @@ public function render(): string
$renderingContext = GeneralUtility::makeInstance(RenderingContextFactory::class)->create([], $request);
}

$renderingContext->setViewHelperVariableContainer($this->renderingContext->getViewHelperVariableContainer());
if (static::shouldUseTemplatePaths()) {
$renderingContext->getTemplatePaths()->setPartialRootPaths(
$this->renderingContext->getTemplatePaths()->getPartialRootPaths()
Expand Down Expand Up @@ -193,6 +193,12 @@ public function render(): string
);
}

// Set custom view to reset rendering stack
$view = new ComponentView($this->parsedTemplate, $renderingContext);
$viewHelperVariableContainer = clone $this->renderingContext->getViewHelperVariableContainer();
$viewHelperVariableContainer->setView($view);
$renderingContext->setViewHelperVariableContainer($viewHelperVariableContainer);

// Render component
return $this->parsedTemplate->render($renderingContext);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<fc:component>
<fc:renderer>
<f:render section="test" />
</fc:renderer>
</fc:component>
<f:section name="test">
A renderer with a section.
</f:section>
1 change: 1 addition & 0 deletions Tests/Functional/ComponentRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public static function renderComponentProvider()
'falseParameter' => false, // strange fluid behavior: will be empty string
], '', 'This is a string|123|1|'],
['DateTimeParameter', ['date' => 1601371704], '', 'Tue, 29 Sep 2020 09:28:24 +0000'],
['WithSection', [], '', 'A renderer with a section.'],
];
}

Expand Down