cycle Tag

Logic Most Useful

Argument(s): various

Documentation

Cycles through list of arguments.

Variable

fruits = ['Apples', 'Bananas', 'Pears', 'Grapes', 'Oranges']

Template

<ol>
{% for fruit in fruits %}
  <li class="{% cycle 'odd' 'even' %}">{{ fruit }}</li>
{% endfor %}
</ol>

Result

<ol>
  <li class="odd">Apples</li>
  <li class="even">Bananas</li>
  <li class="odd">Pears</li>
  <li class="even">Grapes</li>
  <li class="odd">Oranges</li>
</ol>

Commentary


Did we get something wrong? Is there a use case for the cycle tag that we should add? Please let us know.

Send Feedback

Official Documentation
This page last updated on April 14, 2020, 5:59 p.m. EST