Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

CGI Templates

Often dynamic content is generated as a response to a web query. The user types something into a form and a CGI program runs to extract the parameters, search the database, and generate the response. The easiest way to do this is to have the CGI program generate the HTML response. In this section we show a more maintainable way: use the CGI plugin from within a template to access query parameters.

Using the CGI Plugin

The Template Toolkit provides the CGI plugin as a simple wrapper around the CGI module. If you don’t have any particular need to use a CGI object in the calling Perl program—say, to read request parameters or set headers—don’t create one. Instead, use the CGI plugin to create a CGI object from within any templates that require access to it. Example 12-22 shows a template identical to that in Example 12-7, with the exception of the first line, which loads the CGI plugin.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint