Practical mod_perl / HTML Book /



previous page: D.1. Fetching and Installing the Template Toolkit
  
page up: HTML Version of the book
  
next page: D.3. Typical Uses

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.

 

Continue to:

  • prev: D.1. Fetching and Installing the Template Toolkit
  • Table of Contents
  • next: D.3. Typical Uses







TOP
previous page: D.1. Fetching and Installing the Template Toolkit
  
page up: HTML Version of the book
  
next page: D.3. Typical Uses


Menu

  • HTML Book
  • PDF Book
  • Download Code
  • Table of Contents
  • Errata
  • mod_perl2 User's Guide
  • Sitemap

Search


Add to Google




Creative Commons License


Written by
Eric Cholet (Logilune) and
Stas Bekman (StasoSphere & Free Books).


[ Privacy Policy | Terms of Use | About Us | Search ]

© 2007 StasoSphere.com