Dotiac::DTL::Tag::for - The {% for VARIABLE1[|VARIABLE2[|VARIABLE3[|...]]] in VARIABLE %} tag
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]] });
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.
Inside a loop, these variables are set:
The current iteration of the loop, starting with 1.
The current iteration of the loop, starting with 0.
The remaining iterations, starting ending with 1.
The remaining iterations, starting ending with 0.
True if this iteration is the first one.
True if this iteration is the last one.
In nested loops, this is the one above the current
Also sets forloop.key if iterating over a hash.
http://www.djangoproject.com, Dotiac::DTL
Dotiac::DTL was built according to http://docs.djangoproject.com/en/dev/ref/templates/builtins/.
Marc-Sebastian Lucksch
perl@marc-s.de
To install Dotiac::DTL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dotiac::DTL
CPAN shell
perl -MCPAN -e shell install Dotiac::DTL
For more information on module installation, please visit the detailed CPAN module installation guide.