In fluid template I am displaying items list
<f:for each="{myItems}" as="myItem" key="key">
{key}. myItem.name
</f:for>
Here I need to display serial number for each item. for example,
1. myitem one
2. myitem two
etc.
But in my case I used {key} for serial number. But its starting from 0.
0. myitem one
1. myitem two
So how to increment key by 1 for displaying only ?
Thanks.
You can use iteration=""
property and then cycle
. It starts from 1 instead of 0.
<f:for each="{myItems}" as="myItem" iteration="itemIterator">
{itemIterator.cycle}. myItem.name
</f:for>
tip: f:for
iterator contains other useful properties, like isFirst
, isOdd
etc.
Check the wiki for more datails
In Fluid standalone and TYPO3v8 and above:
<f:for each="{myItems}" as="myItem" key="key">
{key + 1}. myItem.name
</f:for>
The key (no pun intended) is the MathExpressionNode and any implementation of Fluid which intentionally disables this implementation will not support this expression - in those cases, iterator.cycle
is your friend.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With