If .. you care passionately about dynamic content creation and management, then this is definitely the book for you. -- PC Plus, Nov 2004 (rating 8/10) - Davey Winder
About the Author
Darren Chamberlain is an active member of the Template Toolkit development team.
David Cross is the owner of Magnum Solutions Ltd., a London-based Perl Consultancy, and is also the author of the well-respected Data Munging with Perl.
Andy Wardley is the author of several CPAN modules including the Template Toolkit. He is a software researcher at the Canon Research Centre Europe and specializes in web-related technologies including dynamic content generation, web application frameworks, and the customization and localization of user interfaces and web content.
Excerpt. © Reprinted by permission. All rights reserved.
This chapter puts the Template Toolkit into context. We show several different ways of using the Template Toolkit to simplify the process of building and managing web site content. We start with some simple examples showing the use of template variables and template components that allow web content to be constructed in a modular fashion. As we progress further into the chapter, we look at more advanced techniques that address the issues of managing the site structure, generating menus and other navigation components, and defining and using complex data.
Although the focus of this chapter is on generating web content, it also serves as a general introduction to the Template Toolkit. It demonstrates techniques that can be adapted to different application areas. This chapter will quickly get you up to speed using the Template Toolkit, but without bogging you down in too much gory detail (were saving that for the rest of the book). We come back to the Web to look at more advanced examples of static and dynamic web content in Chapter 11 and Chapter 12.
Although we may touch briefly on some more advanced issues, we try not to bore you with too much detail, except where it is absolutely necessary to illustrate a key point or explain an important concept. Chapter 3 discusses the syntax and structure of templates and the use of variables, while Chapter 4 covers the various template directives. More information relating to filters and plugins can be found in Chapter 5 and Chapter 6, respectively. More advanced topics concerning the use of the Template Toolkit for generating web content and interfacing to web applications can be found in Chapter 11 and Chapter 12.
We assume a Unix system in the examples in this chapter, but the principles apply
equally well to other operating systems. On a Microsoft Windows machine, for
example, the File Explorer can be used to create folders (directories) and shortcuts
(symbolic links) using the familiar point-and-click interface. Another option we
can highly recommend is to install Cygwin.
Every big web site is made up of individual pages. Lets start with a small and simple page, showing how to eliminate basic repetition using templates. In later sections, we can build on this to generate more pages and add more complex elements.
A Single Page
Example 2-1 shows the HTML markup of a page that displays the customary "Hello World" message, complete with a title, footer, and various other bits of HTML paraphernalia.