NAME
Dotiac::DTL::Tag::cycle - The {% cycle CYCLENAME | VAR1 VAR2 VAR3 VAR4... [as CYCLENAME] %} tag
SYNOPSIS
In a loop:
{% for x in loop %}
<tr class="{% cycle "row1" "row2" variable %}"><td>{{ forloop.counter }}:</td><td>{{ x }}</td></tr>
{# First row is now class="row1" #}
{# Second row class="row2" #}
{# Third row=class="whatever is in {{ variable }}" #}
{# fourth row is again class="row1" and so on.... #}
{% endfor %}
With a name outside a loop
<tr class="{% cycle "row1" "row2" variable as rows %}">...</tr> {# name this cycle with the name "rows" #}
<tr class="{% cycle rows %}">...</tr> {# Same cycle again just the name is needed#}
{% if extrarow %}
<tr class="{% cycle rows %}">...</tr> {# The cycle will only step one forward if extrarow is true #}
{% endif %}
<tr class="{% cycle rows %}">...</tr> {# value now depends on extrarow, even though this is not in the if-block #}
DESCRIPTION
Cycles trough a list of variables on every call.
There are two types of cycles, the ones in a loop, which just need a list of variables and just cycle through them. And the other one is outside of a loop. That one assigns a list of variables to a name and can be called again by that name.
IMPLEMENTATION-SPECIFIC
I don't know about Django, but this implementation also supports this:
{% "A" "B" "X" "Y" as foo %}
{% for x in loop %}
{% cycle foo %} -- {{ x }} -- {% cycle foo %} {# rows are now either A -- x --B or X-- x --Y #}
{% endfor %}
You can also redefine the cycle in this implementation, but beware, the counter is NOT reseted, if you have ABCABC of the cycle "ABC" printed already and then set it to "1234" that will print "ABCABC341234":
{% cycle "A" "B" "X" "Y" as foo %}
{% for x in loop %}
{% ifequal x "4" %} {% cycle "ONE" "one" "TWO" "two" "THREE" "three" as foo %}{% else %}{% cycle foo %}{% endifequal %} -- {{ x }} -- {% cycle foo %} {# rows are now either "A -- x -- B" or "X -- x -- Y" until x is four and then either "ONE -- x -- one" or "TWO -- x -- two" ... #}
{% endfor %}
Reset the cycle-counter in this implementation with an empty variable list: The reset tag will generate no output.
{% cycle "A" "B" "C" "D" as foo %}
{% for x in loop %} {# Lets say loop is [1,2,3,4,5,...] #}
{% ifequal x "3" %}{% cycle as foo %}{% endifequal %}
{% cycle foo %} {# This will now result in "A B A B C D A ..." as it gets reseted before the third time #}
{% endfor %}
BUGS AND DIFFERENCES TO DJANGO
The implementation specific addons might disappear if Django changes the syntax of this tag
SEE ALSO
http://www.djangoproject.com, Dotiac::DTL
LEGAL
Dotiac::DTL was built according to http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
AUTHOR
Marc-Sebastian Lucksch
perl@marc-s.de