Template::FAQ contains Frequently Asked Questions about the Template Toolkit.
Template Toolkit Language
Why doesn't [% a = b IF c %] work as expected?
Because the parser interprets it as
[% a = (b IF c) %]
Do this instead:
[% SET a = b IF c %]
If I'm using TT to write out a TT template, is there a good way to escape [% and %]?
You can do this:
[% stag = "[%"
etag = "%]"
%]
and then:
[% stag; 'hello'; etag %]
Or something like:
[% TAGS [- -] %]
[- INCLUDE foo -] # is a directive
[% INCLUDE foo %] # not a directive, just plain text, passed through
How do I iterate over a hash?
This is covered in the Template::Manual::VMethods section of the manual page. A list of all the keys that are in the hash can be obtained with the 'keys' virtual method. You can then iterate over that list and by looking up each key in turn get the value.
[% FOREACH key = product.keys %]
[% key %] => [% product.$key %]
[% END %]
Product's homepage
Requirements:
· Perl