While a programming language is designed to manipulate data, a presentation language is used to turn the data into plain text, HTML, or some other format. As long as the data is made available to us in a textual representation when we ask for it, we really don’t need to worry too much about how it is stored or computed behind the scenes.
That’s not to say that you can’t create and manipulate variables in templates. However, their most common use is for dealing only with presentation aspects, by using variables to define colors or other layout parameters, displaying the first N search results, or sorting a list of names into alphabetical order, for example. It is unusual (but not unheard of) to use the Template Toolkit to modify data that has any lasting effect. In general, data is passed to a template and then thrown away, so it doesn’t matter if it’s changed in any way.
In this chapter, we take a closer look at the details of the Template Toolkit presentation language. The general syntax of templates comes under scrutiny first, and we give examples of how the default style can be customized using configuration options and template directives. The rest of the chapter is then dedicated to an in-depth study of variables. We describe the various data types, showing how they are defined and used in both Perl and template markup.
We concentrate on the general characteristics of the language without looking too closely at any of the specific directives ...