Search code examples
typo3fluidtypo3-6.2.x

TYPO3 Fluid f:for each iterator


I have a simple question about the f:for ViewHelper in TYPO3 6.2

How is it possible to apply an offset to the iterator to start at index 2?


Example:

<f:for each="{facility.media}" as="media" iteration="iterator">


                             <!-- this index should start at 2-->
    <img src="..." data-lightbox-index="{ iterator.index }">


</f:for>

Thanks for your help.


Solution

  • not possible.

    You might do workarounds.
    you can assign the needed value to a temporary variable. multiple possibilities:

    • use f:cycle (only possible with few entries)
    • use ext:vhs to create/assign the calculated value to a fluid-variable
    • use f:alias to create a local fluid-variable inside your loop.

    for the later two solutions you need the possibility to calculate, which is not given in fluid.
    but you can use a typoscript viewhelper:

    lib.calc = TEXT
    lib.calc {
        current = 1
        prioriCalc = 1
    }
    

    and call it with {f:cObject(typoscriptObjectPath:'lib.calc',data:{iterator.index}+2)}

    <f:for each="{facility.media}" as="media" iteration="iterator">
        <f:alias map="{newIndex:'{f:cObject(typoscriptObjectPath:\'lib.calc\',data:\'{iterator.index}+2\')}'}">
            <img src="..." data-lightbox-index="{newIndex}" />
        </f:alias>
    </f:for>