Project

General

Profile

Actions

Bug #77161

closed

Fluid - IfViewHelper does not work correct in Loop/Partial

Added by Peter Benke almost 8 years ago. Updated almost 8 years ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
Fluid
Target version:
-
Start date:
2016-07-20
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
7
PHP Version:
5.6
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

Hi together,

IfViewHelper does not work correct in Loop/Partial:

ViewHelper:

/**
 * Check Rendering
 * @param string $testmode
 * @return string
 */
public function render($testmode) {

    if($testmode == 'then'){
        return $this->renderThenChild();
    }else{
        return $this->renderElseChild();
    }

}

Template:

<f:for each="{fluidtests}" as="fluidtest" iteration="iteration">

    <vh:childRendering testmode="then">
        <f:then>
            <span style="color:green">Inside Template: Then...</span><br>
        </f:then>
        <f:else>
            <span style="color:red">Inside Template: Else...</span><br>
        </f:else>
    </vh:childRendering>

    <f:render partial="Single" />

</f:for>

Partial:

<vh:childRendering testmode="then">
    <f:then>
        <span style="color:green">Inside Partial: Then...</span><br>
    </f:then>
    <f:else>
        <span style="color:red">Inside Partial: Else...</span><br>
    </f:else>
</vh:childRendering>
<hr>

Output:

Inside Template: Then...
Inside Partial: Then...

Inside Template: Then...
Inside Partial: Else...

Inside Template: Then...
Inside Partial: Else...

This is not correct (Inside Partial: Else...).
It should always be: "Inside Partial: Then..."

Seems, that there is a bug, if I have a partial inside a loop.

See attached Test-Extension.

Thank you.


Files

fluid_test.zip (514 KB) fluid_test.zip Peter Benke, 2016-07-20 09:44
Actions #1

Updated by Georg Ringer almost 8 years ago

  • Status changed from New to Needs Feedback

take a look at https://github.com/TYPO3-extensions/news/blob/master/Classes/ViewHelpers/IfIsActiveViewHelper.php how it should be done. don't use the renderMethod!

does that help for you?

Actions #2

Updated by Nicole Cordes almost 8 years ago

Hi Peter,

just be more verbose on your issue: you are using an implementation if the TYPO3\CMS\Fluid\ViewHelpers\IfViewHelper

That ViewHelper uses an own argument 'condition' which it uses to decide wether to render the then or the else part. That condition is marked as a not required argument without any initialization (means it is false by default). As your ViewHelper gets stored as a cached template, it uses the implementation of the IfViewHelper which internally handles that condition argument. That is why the output of your ViewHelper is not as expected.

IMHO you should use an own implementation of \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper which Georg tried to point out in his post. I don't think this issue is core related (or a bug inside the core) but a problem of the implementation of your ViewHelper.

Actions #3

Updated by Peter Benke almost 8 years ago

Hi Georg,

your advice was perfect, thank you very much!
(But my solution worked without any problems in 6.2 and I could not found anything in the documentation...)

So, you can close this ticket ;-)

@Nicole:
Thank you!
The argument is initialized by annotation, see also:
https://docs.typo3.org/typo3cms/ExtbaseFluidBook/8-Fluid/8-developing-a-custom-viewhelper.html#register-arguments-of-viewhelpers

Actions #4

Updated by Wouter Wolters almost 8 years ago

  • Status changed from Needs Feedback to Closed

Ticket closed as the author solved his problem.

Actions

Also available in: Atom PDF