NAME
Dotiac::DTL::Tag::for - The {% for VARIABLE1[|VARIABLE2[|VARIABLE3[|...]]] in VARIABLE %} tag
SYNOPSIS
Template file:
{% for x in arrayloop %}
{{ forloop.counter }}: {{ x }}
{% endfor %}
{% for x in hashloop %}
{{ forloop.revcounter }}: {{ x }}
{% endfor %}
{% for key,value in hashloop %}
{{key}} is {{ value }}
{% endfor %}
{% for x,y in arrayofarrayloop %}
X = {{ x }}, Y = {{ y }}
{% endfor %}
{% for x in emptyloop %}
{{ forloop.counter }}: {{ x }}
{% empty %}
The loop is empty
{% endfor %}
Perl-file:
$t=Dotiac::DTL->new("page.html");
$t->print(
{
arrayloop=>[1 .. 10],
hashloop=>{A=>1,B=>2,C=>3,D=>4},
arrayofarrayloop=[[1,10],[2,20],[3,30]]
});
DESCRIPTION
Iterates over a datastructure, assigns the variable to every element of an array or hash and runs the included templatecode with it.
If the loop is empty and an {% empty %} tag is given, it will run the templatecode from {% empty %} to {% endfor %}.
If given one variable to assign with a hash, it will set it to the value, if given two, it will assign the key to the first and the value to the second variable.
If given more than one variable and a array of arrays, it will assagin the variables to the hash content.
See also http://docs.djangoproject.com/en/dev/ref/templates/builtins/#for for more details and examples.
the forloop variable.
Inside a loop, these variables are set:
- forloop.counter
-
The current iteration of the loop, starting with 1.
- forloop.counter0
-
The current iteration of the loop, starting with 0.
- forloop.revcounter
-
The remaining iterations, starting ending with 1.
- forloop.revcounter0
-
The remaining iterations, starting ending with 0.
- forloop.first
-
True if this iteration is the first one.
- forloop.last
-
True if this iteration is the last one.
- forloop.parentloop
-
In nested loops, this is the one above the current
BUGS AND DIFFERENCES TO DJANGO
Also sets forloop.key if iterating over a hash.
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