Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
CHAPTER 11 Advanced Static Web Page Techniques In Chapter 2, we looked at some simple examples of using the Template Toolkit to generate web content. In this chapter, we will look at some more advanced techniques for building web sites and manipulating HTML page content. We will start out with a minimal setup that illustrates some useful techniques that can easily be adapted and applied to any web site. The basic system will be extended throughout the chapter as we add functionality to address more complex requirements and provide more ad- vanced features. The emphasis in this chapter will be on generating static HTML web content. The examples will be loosely based around the Template Toolkit web site, http://template -toolkit.org/. However, we're not going to be looking at content of any of the individual pages in any great detail, so the subject matter is largely immaterial. Most of the techniques demonstrated are equally applicable to web sites delivering dynamically generated content and running web applications. More generally, this chapter shows how a general-purpose presentation framework can be built using the Template Toolkit. This can then be used to apply a consistent look and feel to all pages in a site, including static HTML pages (as discussed later in this chapter) and dynamic content (described in Chapter 12). Getting Started A few basic tasks need to be done when starting out a project for a Template Toolkit- driven web site. The first thing is to create somewhere for the project files to go. It's a good idea to keep everything related to the project in one place. If all the files are located in subdirectories of one common parent directory, the entire project can easily be re- located to another server, or perhaps to another directory on the same machine. It is much harder to keep track of files when they are dotted around a filesystem. For this project, we will generate static HTML pages from templates. All the output files will be written to an html subdirectory of the project directory. From here they can be accessed via an appropriately configured web server. We'll be looking at a simple configuration for the Apache web server that demonstrates this. 393