I am trying to write the following if condition in fluid but it is not working as I would hope.
Condition
As part of a for loop I want to check if the item is the first one or 4th, 8th etc
I would have thought the following would work but it display the code for every iteration.
<f:if condition="{logoIterator.isFirst} || {logoIterator.cycle % 4} == 0">
I have managed to get it working with a nested if but it just feels wrong having the same section of code twice and also having the cycle check use a <f:else>
instead of == 0
<f:if condition="{logoIterator.isFirst}">
<f:then>
Do Something
</f:then>
<f:else>
<f:if condition="{logoIterator.cycle} % 4">
<f:else>
Do Something
</f:else>
</f:if>
</f:else>
</f:if>
Best Answer
TYPO3 v8
Updated the answer for TYPO3 v8. This is quoted from Claus answer below:
TYPO3 6.2 LTS and 7 LTS
For more complex if-Conditions (like several or/and combinations) you can add your own ViewHelper in
your_extension/Classes/ViewHelpers/
. You just have to extend FluidsAbstractConditionViewHelper
. The simple if-ViewHelper that shipps with Fluid looks like this:All you have to do in your own ViewHelper is to add more parameter than
$condition
, like$or
,$and
,$not
etc. Then you just write your if-Conditions in php and render either the then or else child. For your Example, you can go with something like this:The File would be in your_extension/Classes/ViewHelpers/ExtendedIfViewHelper.php Then you have to add your namespace in the Fluid-Template like this (which enables all your self-written ViewHelpers from your_extension/Classes/ViewHelpers/ in the template:
and call it in your template like this:
Edit: updated.