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 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
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: <, >, &.
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 %]
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 ...