2
votes

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.

3

3 Answers

1
votes

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>
1
votes

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>
1
votes

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