Dotiac

 view release on metacpan or  search on metacpan

lib/Dotiac/DTL/Tag/for.pm  view on Meta::CPAN

=head1 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]]
		});

=head1 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 L<http://docs.djangoproject.com/en/dev/ref/templates/builtins/#for> for more details and examples.

=head2 the forloop variable.

Inside a loop, these variables are set:

=over

=item forloop.counter

The current iteration of the loop, starting with 1.

=item forloop.counter0

The current iteration of the loop, starting with 0.

=item forloop.revcounter

The remaining iterations, starting ending with 1.

=item forloop.revcounter0

The remaining iterations, starting ending with 0.

=item forloop.first

True if this iteration is the first one.

=item forloop.last

True if this iteration is the last one.

=item forloop.parentloop

In nested loops, this is the one above the current

=back

=head1 BUGS AND DIFFERENCES TO DJANGO

Also sets forloop.key if iterating over a hash.

=head1 SEE ALSO

L<http://www.djangoproject.com>, L<Dotiac::DTL>

=head1 LEGAL

Dotiac::DTL was built according to http://docs.djangoproject.com/en/dev/ref/templates/builtins/.

=head1 AUTHOR

Marc-Sebastian Lucksch

perl@marc-s.de

=cut



( run in 0.895 second using v1.01-cache-2.11-cpan-71847e10f99 )