HTML::Template::Filters - HTML::Template support module, which contains some useful filters.
use HTML::Template::Filters qw(get_filters); my $filters = get_filters( HT_FILTER_ALLOW_TRAILING_SLASH, HT_FILTER_TMPL_COMMENT, HT_FILTER_TMPL_SET, ); my $ht = new HTML::Template( filename => 'somefile.tmpl', filter => $filters, );
This is a support module for HTML::Template, which contains a collection of filters that can be applied to a HTML::Template object.
Filters are applied in the order that they are specified. As such, you may need to take this into account in some situations.
Filters currently available (detailed below): HT_FILTER_STRIP_TMPL_NEWLINE_WHITESPACE HT_FILTER_VANGUARD_COMPATIBILITY HT_FILTER_ALLOW_TRAILING_SLASH HT_FILTER_SSI_INCLUDE_VIRTUAL HT_FILTER_STRIP_TMPL_NEWLINE HT_FILTER_GZIPPED_TEMPLATES HT_FILTER_PERCENT_VARIABLES HT_FILTER_STRIP_REDUNDANT HT_FILTER_STRIP_NEWLINE HT_FILTER_TMPL_CONSTANT HT_FILTER_TMPL_COMMENT HT_FILTER_TMPL_FIXME HT_FILTER_MAC_OS
Strip any trailing newline and subsequence whitespace from the nextline, when using closing TMPL_xxx tags.
Implements the H::T option of 'vanguard compatibility'. See 'PERCENT_VARIABLES'.
Note, doesn't set 'die_on_bad_params=0' (ie you may want/need to do this yourself).
Enable HTML::Template to support the parsing of a trailing slash within template tags, as in the following:
<TMPL_IF somevar /> <TMPL_VAR anothervar /> </TMPL_IF />
This may be useful for you if you use a HTML validating editor, which likes to see empty tags written as <... />.
SSI (server side includes) virtual includes
Translate SSI (server side includes) virtual includes, into H::T includes.
<!-- #include virtual="some_include" -->
Strip any trailing newlines from starting TMPL_xxx tags.
This filter allows you GZip your templates, which it will uncompress them, before parsing them, as in:
-> file stored as: index.tmpl.gz -> parsed by H::T as: index.tmpl
Note that since the templates are small files already, this capability, although quite cool, is rather stupid...!
Allows you to use syntax like:
... %some_variable% ...
within your templates. You may consider this to be nicer looking than:
... <TMPL_VAR NAME="some_variable"> ...
Allows the following syntax within templates:
<TMPL_SET NAME="template_var" VALUE="some_value">
This will then translate all <TMPL_VAR NAME="template_var">'s into "some_value". Doesn't work for <TMPL_LOOP ..>'s as loops require the template variable to be an array (rather than a scalar). Also, dont specify ESCAPE or DEFAULT arguments to the TMPL_VAR as, they make no sense when used with TMPL_SET.
Allows the TMPL_COMMENT tag so that any text between the start/end tag is stripped, as in:
<TMPL_COMMENT>Any text between comments is stripped</TMPL_COMMENT>
Same as TMPL_COMMENT (makes for searching of FIXME's)
Join a TMPL_LOOP param, using the required field and seperator. Equivalent to Perl join(). The field and seperator are optional.
If using 'scalar_loops' you can easily push a simple Perl array into the template, which can then be TMPL_JOIN'ed.
Note: this filter requires the use of 'loop_context_vars'.
Converts the '\r' Mac OS linefeed character to '\n' so that H::T can parse the template.
You can send bug reports to the HTML::Template mailing-list. To join the list, visit:
The users of the HTML::Template mailing list contributed the idea and some patterns for the implementation of this module.
Mathew Robertson <email@example.com>
This module is released under the same license that HTML::Template is released under.