Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame^] | 1 | ``cycle`` |
| 2 | ========= |
| 3 | |
| 4 | The ``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 | |
| 15 | The 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 | |
| 25 | Arguments |
| 26 | --------- |
| 27 | |
| 28 | * ``position``: The cycle position |