The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Dotiac::DTL::Tag::importloop - The {% importloop ARRAYOFHASHES [reversed] [merge] [contextvars] %} tag

SYNOPSIS

Variables:

posts=>[
	{Title=>"test",Content="A test post",Date=>time},
	{Title=>"My first post",Content="Nothing to say here",Date=>time-3600}
]

Template file:

{% importloop posts %}
	<h1>{{ Title }}</h1> {# Title is now in the main namespace #}
	{{ Content|linebreaks }}
	<em>{{ Date|date:jS F Y H:i" }}</em>
{% empty %}
	No entries
{% endimportloop %}

DESCRIPTION

Iterates over a an ARRAY OF HASHES and imports those hashes into the top-level namespace.

If the loop is empty and an {% empty %} tag is given, it will run the templatecode from {% empty %} to {% endimportloop %}.

This tag works almost like HTML::Template's TMPL_LOOP tag.

reversed

If reversed is put after the source the list/array is reversed before the iteration

merge

If merge is given, the namespace is not replaced (default), but merged with the content of the hash.

contextvars

Similar to HTML::Template's loop_context_vars option, adds some variables into the namespace about the loop

__first__

True if this is the first iteration

__inner__

True if this is neither the first nor the last iteration.

__last__

True if this is the last iteration.

If there is only one iteration, __first__ and __last__ are both true, but not __inner__

__counter__

The current iteration, 1 indexed.

__odd__

True on the first line and every other line (first, third, fifth and so on)

BUGS AND DIFFERENCES TO DJANGO

Also sets importloop.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