Attention
TYPO3 v11 has reached end-of-life as of October 31th 2024 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.
Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v11 here: TYPO3 ELTS.
Cycle ViewHelper <f:cycle>
This ViewHelper cycles through the specified values. This can be often used to specify CSS classes for example.
To achieve the "zebra class" effect in a loop you can also use the "iteration" argument of the for ViewHelper.
Examples
These examples could also be achieved using the "iteration" argument of the ForViewHelper.
Simple
<f:for each="{0:1, 1:2, 2:3, 3:4}" as="foo">
<f:cycle values="{0: 'foo', 1: 'bar', 2: 'baz'}" as="cycle">
{cycle}
</f:cycle>
</f:for>
Output:
foobarbazfoo
Alternating CSS class
<ul>
<f:for each="{0:1, 1:2, 2:3, 3:4}" as="foo">
<f:cycle values="{0: 'odd', 1: 'even'}" as="zebraClass">
<li class="{zebraClass}">{foo}</li>
</f:cycle>
</f:for>
</ul>
Output:
<ul>
<li class="odd">1</li>
<li class="even">2</li>
<li class="odd">3</li>
<li class="even">4</li>
</ul>
Source code
Go to the source code of this ViewHelper: CycleViewHelper.php (GitHub).
Arguments
The following arguments are available for <f:
:
values
-
- Type
- mixed
The array or object implementing ArrayAccess (for example SplObjectStorage) to iterated over
as
-
- Type
- mixed
- Required
true
The name of the iteration variable