[ Team LiB ] Previous Section Next Section

D.2 Overview

The Template Toolkit is a collection of Perl modules, scripts, and other useful bits and pieces that collectively implement a powerful template processing system for generating and manipulating content. It scans through source documents looking for special directives embedded in the text. These act as instructions to the processor to perform certain tasks.

A simple directive might just insert the value of a variable:

<a href="[% home %]">Home</a>

or perhaps include and process another template:

[% INCLUDE header
     title = 'A Dark and Stormy Night'
%]

More complex directives may make use of the powerful language constructs that the Template Toolkit provides. For example:

<h3>[% users.size %] users currently logged in:</h3>
<ul>
[% FOREACH user = users %]
   [%# 'loop' is a reference to the FOREACH iterator -%]
   <li>[% loop.count %]/[% loop.size %]: 
       <a href="[% user.home %]">[% user.name %]</a>
   [% IF user.about %]
       <p>[% user.about %]</p>
   [% END %]
   [% INCLUDE userinfo %]
   </li>
[% END %]
</ul>

Chances are that you can work out what most of the above is doing without too much explanation. That's the general idea—to keep the templates as simple and general as possible. It allows you to get a broad overview of what's going on without too much detail getting in the way.

We'll come back to this example later on and explain a little more about what's going on.

    [ Team LiB ] Previous Section Next Section