Skip to content

Commit 4ea540e

Browse files
smichaelsenmbrodala
authored andcommitted
[BUGFIX] Fix contentAs feature when used on Layout level
`<f:render section="MySection" contentAs="content">some content</f:section>` did not work when called from a Layout because the `contentAs` variable was not passed to the template section in that case.
1 parent 2d2d5db commit 4ea540e

File tree

6 files changed

+44
-0
lines changed

6 files changed

+44
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<f:layout name="ContentAs" />
2+
3+
<f:render section="Main" contentAs="content">Content from layout via contentAs</f:section>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<f:layout name="ContentAs" />
2+
3+
<f:section name="Main">
4+
{content}
5+
</f:section>

examples/example_layoutcontentas.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* EXAMPLE: MVC pattern used with TYPO3.Fluid
5+
*
6+
* This examples shows how TYPO3.Fluid is integrated
7+
* in an MVC context, highlighting which parts may
8+
* be replaced in order to adapt the engine to your
9+
* favorite MVC framework.
10+
*
11+
* The alternative to this is single file rendering
12+
* - see the other example for that.
13+
*/
14+
15+
require __DIR__ . '/include/view_init.php';
16+
17+
// Assign Layout name as ViewVariable which we will pass to f:layout as name
18+
$view->assign('layout', 'Dynamic');
19+
20+
// Set the template path and filename we will render
21+
$view->getTemplatePaths()->setTemplatePathAndFilename(__DIR__ . '/Resources/Private/Singles/ContentFromLayout.html');
22+
23+
$output = $view->render();
24+
25+
// Output of Controller "Default" action "Default" using helper from view_init.php
26+
example_output($output);

src/View/AbstractTemplateView.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ public function renderSection($sectionName, array $variables = [], $ignoreUnknow
221221
if ($this->getCurrentRenderingType() === self::RENDERING_LAYOUT) {
222222
// in case we render a layout right now, we will render a section inside a TEMPLATE.
223223
$renderingTypeOnNextLevel = self::RENDERING_TEMPLATE;
224+
foreach ($variables as $key => $value) {
225+
$renderingContext->getVariableProvider()->add($key, $value);
226+
}
224227
} else {
225228
$renderingContext = clone $renderingContext;
226229
$renderingContext->setVariableProvider($renderingContext->getVariableProvider()->getScopeCopy($variables));

tests/Functional/ExamplesTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ public function getExampleScriptTestValues()
240240
'Rendered via DynamicLayout, section "Main":',
241241
]
242242
],
243+
'example_layoutcontentas.php' => [
244+
'example_layoutcontentas.php',
245+
[
246+
'Content from layout via contentAs',
247+
]
248+
],
243249
'example_cachestatic.php' => [
244250
'example_cachestatic.php',
245251
[

tests/Unit/View/TemplatePathsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ public function testResolveFilesInFolders()
220220
[['examples/Resources/Private/Layouts/', 'examples/Resources/Private/Templates/Default/'], 'html']
221221
);
222222
$expected = [
223+
'examples/Resources/Private/Layouts/ContentAs.html',
223224
'examples/Resources/Private/Layouts/Default.html',
224225
'examples/Resources/Private/Layouts/Dynamic.html',
225226
'examples/Resources/Private/Templates/Default/Default.html',

0 commit comments

Comments
 (0)