Directive Summary
- GET - Evaluate and print a variable or value.
[% GET variable %] # 'GET' keyword is optional [% variable %] [% hash.key %] [% list.n %] [% code(args) %] [% obj.meth(args) %] [% "value: $var" %]
- SET - Assign a values to variables.
[% SET variable = value %] # 'SET' also optional [% variable = other_variable variable = 'literal text @ $100' variable = "interpolated text: $var" list = [ val, val, val, val, ... ] list = [ val..val ] hash = { var => val, var => val, ... } %]
- DEFAULT - Like SET above, but variables are only set if currently unset (i.e. have no true value).
[% DEFAULT variable = value %]
- INSERT - Insert a file without any processing performed on the contents.
[% INSERT legalese.txt %]
- INCLUDE - Process another template file or block and include the output. Variables are localised.
[% INCLUDE template %] [% INCLUDE template var = val, ... %]
- PROCESS - As INCLUDE above, but without localising variables.
[% PROCESS template %] [% PROCESS template var = val, ... %]
- WRAPPER - Process the enclosed block WRAPPER … END block then INCLUDE the named template, passing the block output in the 'content' variable.
[% WRAPPER template %] content... [% END %]
- BLOCK - Define a named template block for subsequent INCLUDE, PROCESS, etc.,
[% BLOCK template %] content [% END %]
- FOREACH - Repeat the enclosed FOREACH … END block for each value in the list.
[% FOREACH variable = [ val, val, val ] %] # either [% FOREACH variable = list %] # or [% FOREACH list %] # or content... [% variable %] [% END %]
- WHILE - Enclosed WHILE … END block is processed while condition is true.
[% WHILE condition %] content [% END %]
- IF / UNLESS / ELSIF / ELSE - Enclosed block is processed if the condition is true / false.
[% IF condition %] content [% ELSIF condition %] content [% ELSE %] content [% END %] [% UNLESS condition %] content [% # ELSIF/ELSE as per IF, above %] content [% END %]
- SWITCH / CASE - Multi-way switch/case statement.
[% SWITCH variable %] [% CASE val1 %] content [% CASE [ val2, val3 ] %] content [% CASE %] # or [% CASE DEFAULT %] content [% END %]
- MACRO - Define a named macro.
[% MACRO name <directive> %] [% MACRO name(arg1, arg2) <directive> %] ... [% name %] [% name(val1, val2) %] * **FILTER** - Process enclosed FILTER ... END block then pipe through a filter. [% FILTER name %] # either [% FILTER name( params ) %] # or [% FILTER alias = name( params ) %] # or content [% END %]
- USE Load a "plugin" module, or any regular Perl module if LOAD_PERL option is set.
[% USE name %] # either [% USE name( params ) %] # or [% USE var = name( params ) %] # or ... [% name.method %] [% var.method %]
- TRY / THROW / CATCH / FINAL - Exception handling.
[% TRY %] content [% THROW type info %] [% CATCH type %] catch content [% error.type %] [% error.info %] [% CATCH %] # or [% CATCH DEFAULT %] content [% FINAL %] this block is always processed [% END %]
- NEXT - Jump straight to the next item in a FOREACH/WHILE loop.
[% NEXT %]
- LAST - Break out of FOREACH/WHILE loop.
[% LAST %]
- RETURN - Stop processing current template and return to including templates.
[% RETURN %]
- STOP - Stop processing all templates and return to caller.
[% STOP %]
- TAGS - Define new tag style or characters (default: [% %]).
[% TAGS html %] [% TAGS <!-- --> %]
- COMMENTS - Ignored and deleted.
[% # this is a comment to the end of line foo = 'bar' %] [%# placing the '#' immediately inside the directive tag comments out the entire directive %]