cycle
Tag
Accepts a list of strings as parameters and cycles through each one and outputs it.
Description
Accepts a list of strings as parameters and cycles through each one and outputs it. Each time
cycle
is called, the next string that was passed in as a parameter is output.
cycle
must be used within a
for
loop.
{% for i in (1..5) %} {% cycle 'apple', 'banana', 'orange' %} {% endfor %}
Output
apple banana orange apple banana
Uses for cycle
include the following:
- Applying odd/even classes to rows in a table.
- Applying a unique class to the last item in each row.
Parameters
-
group
string
If you need to have more than one set of cycle
s running
independently within a template, you can prepend a group name to the beginning of the
parameters.
<ul> {% for link in navigation.links %} <li class="{% cycle 'links': '', 'last' %}"> {{ link.title }} </li> {% endfor %} {% for category in categories %} <li class="{% cycle 'categories': '', '', 'last' %}"> {{ category.name }} </li> {% end %} </ul>