TYPO3 Fluid f:for each iterator

10,812

Solution 1

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>

Solution 2

You can do this using fluid ForViewHelper like below.

Using Index and Index start always 0. So, you can do this like below condition.

<f:for each="{facility.media}" as="media" iteration="iterator">
    <f:if condition="{iterator.index} >= 2">
          <img src="..." data-lightbox-index="{ iterator.index }">
    </f:if>
</f:for>

Using Cycle and cycle always start with 1.

<f:for each="{facility.media}" as="media" iteration="iterator">
    <f:if condition="{iterator.cycle} >= 3">
          <img src="..." data-lightbox-index="{ iterator.index }">
    </f:if>
</f:for>

For more ForViewHelper

Solution 3

you can use an additional f:if

<f:for each="{facility.media}" as="media" iteration="iterator">
    <f:if condition="{iterator.index} > 2">
          <img src="..." data-lightbox-index="{ iterator.index }">
    </f:if>
</f:for>
Share:
10,812

Related videos on Youtube

Robin
Author by

Robin

Updated on June 04, 2022

Comments

  • Robin
    Robin almost 2 years

    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.

  • Robin
    Robin almost 7 years
    doesn't work. image 1 and image 2 wouldn't be displayed.