Bug #77161
closedFluid - IfViewHelper does not work correct in Loop/Partial
0%
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
Updated by Georg Ringer over 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?
Updated by Nicole Cordes over 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.
Updated by Peter Benke over 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
Updated by Wouter Wolters over 8 years ago
- Status changed from Needs Feedback to Closed
Ticket closed as the author solved his problem.