TYPO3 / Fluid

Fluid template rendering engine - Standalone version
GNU Lesser General Public License v3.0
152 stars 93 forks source link

Bug: Nested switch viewhelper seems not working (in some cases) #428

Open isikbattenstein opened 5 years ago

isikbattenstein commented 5 years ago

I created a cutom template for textmedia with a switch statement to load certain partials depending on layout.

At first I used the if viewhelper and everything worked fine. After I replaced the if viewhelper with the swich viewhelper, certain textmedias didn't load any more. After some research I found out that the header partial has to be the reason more concrete the switch statement inside header.

tantegerda1 commented 5 years ago

I just tried different nested f:switch scenarios and could not reproduce your issue. Could you share a minimal template/variables combination that reliably reproduces the error?

isikbattenstein commented 5 years ago

I made a Textmedia Template, that looks like this:

 <f:switch expression="{data.layout}">
        <f:case value="0"><f:render partial="Textmedia/Default" arguments="{_all}"/></f:case>
        <f:case value="2"><f:render partial="Textmedia/TextInImage" arguments="{_all}"/></f:case>
        <f:case value="3"><f:render partial="Textmedia/List" arguments="{_all}"/></f:case>
        <f:case value="4"><f:render partial="Textmedia/PageHeader" arguments="{_all}"/></f:case>
        <f:case value="5"><f:render partial="Textmedia/TextBesidesImage" arguments="{_all}"/></f:case>
        <f:case value="6"><f:render partial="Textmedia/CenteredText" arguments="{_all}"/></f:case>
    </f:switch>

Some of these generates calls the "Header/All.html", but some not. Every Texemedia Partial that calls a header Element will not be rendered. I created a customized Partial Header.html, but it look mostly the same, I just added 3 cases:

   <f:case value="6">
            <h1 class="{positionClass} white text-shadow">
                <f:link.typolink parameter="{link}">{header}</f:link.typolink>
            </h1>
        </f:case>
        <f:case value="7">
            <h3 class="{positionClass} white">
                <f:link.typolink parameter="{link}">{header}</f:link.typolink>
            </h3>
        </f:case>
        <f:case value="8">
            <h2 class="{positionClass} white">
                <f:link.typolink parameter="{link}">{header}</f:link.typolink>
            </h2>
        </f:case>

That's what can I say for now.

vertexvaar commented 5 years ago

I can reproduce this error. Nested f:switch ViewHelpers sometimes fail to restore the "previous switch state" (The values of switchExpression and break in the ViewHelperVariableContainer). When the previous break value is not restored to true the SwitchViewHelper will continue to render the defaultCase after rendering the case that actuall matched.

My working example is in the attached ZIP. Run composer install and test.php and you will see the output "CASE: Default". On the second run you will see "<h2 class="">Some header</h2>". The bug is only reproducible when there is no cache thus the SwitchViewHelper is not compiled yet.

testfluid.zip [The folder cache has to be created manually]

I think the problem is somewhere in the recursion of the Header partial in the f:defaultCase CiewHelper (original taken from fluid_styled_content).

hilburger commented 3 years ago

Hi everybody! I still get this on the latest 10.4. Is the any news on this? hanks!

hilburger commented 3 years ago

Could this be the same problem? https://github.com/TYPO3/Fluid/issues/514