In Chapter 2 and Chapter 11, we looked at some basic, and then some more advanced techniques for generating static web content. The fundamental limitation of static web pages is, rather obviously, that they are static. The Template Toolkit allows you to incorporate any kind of dynamic data into a template as it is being processed. But once the page has been generated, the data is fixed. If you want to use different data, you must process the template again.
Most web content is static. The page is generated offline from a template, using a page design tool, or perhaps just typed in at a text editor. It is then uploaded to the web server where it is delivered time and time again without changing. Simple, fast, and efficient.
Some web content is dynamic. The results from a search engine are a perfect example of a dynamically generated page. There’s no way of generating the page in advance because you don’t know what search terms the user is going to enter. There are many other examples of dynamically generated web content to be found at news sites, in bulletin boards and chat rooms, and of course in e-commerce applications, where pages showing the latest offers or the contents of a user’s shopping cart must be generated dynamically to incorporate the latest live data.
In this chapter, we will look at generating dynamic web pages using the Template Toolkit. We will start with some simple CGI scripts to illustrate the basic principles, ...