cycle

Loops through a group of strings and outputs them in the order that they were passed as parameters.
Each time cycle is called, the next string that was passed as a parameter is output.

cycle must be used within a for loop block.

Input
  • {% cycle 'one', 'two', 'three' %}
    {% cycle 'one', 'two', 'three' %}
    {% cycle 'one', 'two', 'three' %}
    {% cycle 'one', 'two', 'three' %}
Output
  • one
    two
    three
    one

Group name

If no name is supplied for the cycle group, then it’s assumed that multiple calls with the same parameters are one group.

To have total control over cycle groups, optionally specify the name of the group. This can even be a variable.

Input
  • {% cycle 'group 1': 'one', 'two', 'three' %}
    {% cycle 'group 1': 'one', 'two', 'three' %}
    {% cycle 'group 2': 'one', 'two', 'three' %}
    {% cycle 'group 2': 'one', 'two', 'three' %}
Output
  • one
    two
    one
    two