Perl
  Home arrow Perl arrow Page 6 - Building a Complete Website using the ...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PERL

Building a Complete Website using the Template Toolkit
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 29
    2004-09-15

    Table of Contents:
  • Building a Complete Website using the Template Toolkit
  • A “Hello World” HTML Template
  • Benefits of Modularity
  • Loading the Configuration Template
  • Creating a Project Directory
  • A Place for Everything, and Everything in Its Place
  • Adding Headers and Footers Automatically
  • More Template Components
  • Setting Default Values
  • Wrapper and Layout Templates
  • Using Layout Templates
  • Menu Components
  • Structured Configuration Templates
  • Layered Configuration Templates
  • Assessment

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    Building a Complete Website using the Template Toolkit - A Place for Everything, and Everything in Its Place
    (Page 6 of 15 )

    Before we can run the build script to generate the site content, we will need to move our page and library template files into place.

    The source templates for the HTML pages should now be moved into the src direc tory where ttree can find them. The HTML files that ttree generates in the html output directory will be given the same filename as the src template from which they are generated. For this reason, we’ll be using a .html file extension on our page templates from now on.

    Also, move the template components config, header, and footer into the lib directory. These are (for now) also identical to those shown in the earlier examples.

    Running the Build Script

    Now we can run the bin/build script to invoke ttree to build the site content:

    $ bin/build
    ttree 2.63 (Template Toolkit version 2.10)

          Source: /home/dent/web/src
     Destination: /home/dent/web/html
    Include Path: [ /home/dent/web/lib ]
          Ignore: [ \b(CVS|RCS)\b, ^# ]
            Copy: [ \.(png|gif|jpg)$ ]
          Accept: [ * ]

    + earth.html
    + magrethea.html

    The sample output from ttree shown here indicates that two page templates, earth.html and magrethea.html, were found in the src directory. The + character to the left of the filenames indicates that the templates were processed successfully. Corresponding earth.html and magrethea.html files will have been created in the html directory con taining the output generated by processing the templates.

    Now that we’ve set up ttree and told it where our page templates are located, we can add new pages to the site by simply adding them to the src directory. When you next run the build script, ttree will locate the new page templates, even if they’re located deep in a subdirectory (thanks to the recurse option), and process them into the corresponding place in the html directory.

    You can now build all the static web pages in your site using a single, simple command.

    Skipping Unmodified Templates

    When ttree is run it tries to be smart in working out which templates need to be processed and which don’t. It does this by comparing the file modification time of the page template with the corresponding output file (if any) that it previously generated.

    Run the bin/build script again, and the + characters to the left of the filename change to the - character:

    $ bin/build
    ttree 2.63 (Template Toolkit version 2.10)

          Source: /home/dent/web/src
     Destination: /home/dent/web/html
    Include Path: [ /home/dent/web/lib ]
          Ignore: [ \b(CVS|RCS)\b, ^# ]
            Copy: [ \.(png|gif|jpg)$ ]
          Accept: [ * ]

    -earth.html       (not modified)
    -magrethea.html   (not modified)

    This indicates that the templates weren’t processed the second time around, with the message to the right of the filenames explaining why. In this case, ttree has recog nized that the source templates, src/earth.html and src/magrethea.html, haven’t been modified since the corresponding output files, html/earth.html and html/magrethea. html, were created. Given that nothing has changed, there’s no need to reprocess the templates.

    There may be times when you want to force ttree to build a particular page or even all the pages on the site, regardless of any file modification times. You can process one or more pages by naming them explicitly on the command line:

    $ bin/build earth.html magrethea.html

    One time that you might want to force all pages to be rebuilt is when you modify a header, footer, or some other template component that is used by all the pages. Unfortunately, ttree isn’t smart enough to figure out which library templates are used by which page templates. * The
    -a option tells ttree to ignore file modification times and process all page templates, regardless:

    $ bin/build -a

    Buy the book!If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!

    Visit the O'Reilly Network http://www.oreillynet.com for more online content.

    More Perl Articles
    More By O'Reilly Media


     

       

    PERL ARTICLES

    - Perl: A Continuing Look at Hashes and Multid...
    - Perl: Another Round with Hashes
    - Perl Hashes
    - Perl Lists: A Final Look at List::Util
    - Perl Lists: Utilizing List::Util
    - Perl Lists: The Split() Function
    - SQL and CGI with Perl and DBI
    - Perl Lists: More Functions and Operators
    - SELECT Queries and Perl
    - Perl Lists: More on Manipulation
    - Creating a Database with Perl and DBI
    - Perl: Sailing the List(less) Seas
    - Perl and DBI
    - Perl: Concatenating Text and More
    - Perl Text: Quoting Without Quote Marks

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway