NAME
App::Dapper::Filters - Default template filters available to all projects.
DESCRIPTION
Filters contained here can be called from layout and source files using the filter/pipe mechanism of the template language. Example:
[% page.title | xml_escape %]
They are in addition to the filters and methods built in to Template::Alloy, such as html, upper and json. These filters only apply to text: given a hash, a list or an object (such as a date) they print nothing. For dates use the xmlschema method ([% page.date.xmlschema %]); for dumping variables use the built-in json method ([% page.json(1) %]).
filters
Returns the hash of filters in the form expected by the FILTERS option of Template::Alloy. Filters that take arguments (like replace_last) are registered as dynamic filters so the arguments reach them.
xml_escape
Escape a string so that it can be included in XML or HTML files. The characters &, <, >, " and ' are replaced with entities.
date_to_xmlschema
Convert a date string to an XML Schema date that also includes the timezone.
[% "2014-05-02T10:30:00-05:00" | date_to_xmlschema %]
Filters only apply to text in templates, so for page.date and site.time (which are date objects) use their xmlschema method instead:
[% page.date.xmlschema %]
Called from Perl, it also accepts a DateTime object.
replace_last
Replace the last occurrence of a string with another string. The string is matched literally, not as a regular expression.
[% "a, b, c" | replace_last(", ", " and ") %] # a, b and c
smart
Replace --- with an em dash (—) and -- with an en dash (–). Longer runs of dashes are left alone.