Advanced Templates for Slash

As mentioned earlier, Slash adds some special magic to the Template Toolkit to perform its necessary magic. While the following manipulations all retain the essential flavor of TT2, Slash adds some handy idioms and tools.

Filters

Filters process the output of a block. They can perform any type of manipulation imaginable. In Slash templates, filters generally remove bad HTML and modify formatting as necessary. A standard FILTER directive converts significant HTML characters into their appropriate entities:

[% FILTER html %]
	These three bad boys are Trouble in raw HTML:  <, >, &.
[% END %]

This produces the following output, which ought to display properly in any web browser:

These three bad boys are Trouble in raw HTML: &lt;, &gt;, &amp;.

As usual, the Slash templates often take advantage of template shortcuts, running a variable through a filter and returning the result in one statement. These two lines are functionally equivalent:

Here is some HTML: [% FILTER html; potential_code; END %]
Here is some HTML: [% potential_code | html %]

Slash Filters

Because it must deal with data from many different clients and from users with a wide range of skills and attitudes (from careless to malicious), Slash provides several of its own filters. These do everything from screening out unwanted HTML codes (no pop-up windows or embedded banner ads!) to creating valid URLs. For the morbidly curious, the real functions may be found in Slash::Utility::Data, but are ...

Get Running Weblogs with Slash now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.