O'Reilly logo

Running Weblogs with Slash by David Krieger, Brian Aker, Chromatic

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required