blob: 84cff6a1d5a2d0e3794938389bac92880da54dae [file] [log] [blame]
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01001``cycle``
2=========
3
4The ``cycle`` function cycles on an array of values:
5
6.. code-block:: twig
7
8 {% set start_year = date() | date('Y') %}
9 {% set end_year = start_year + 5 %}
10
11 {% for year in start_year..end_year %}
12 {{ cycle(['odd', 'even'], loop.index0) }}
13 {% endfor %}
14
15The array can contain any number of values:
16
17.. code-block:: twig
18
19 {% set fruits = ['apple', 'orange', 'citrus'] %}
20
21 {% for i in 0..10 %}
22 {{ cycle(fruits, i) }}
23 {% endfor %}
24
25Arguments
26---------
27
28* ``position``: The cycle position