Perl Programming Page 6 - Building a Complete Website using the Template Toolkit |
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 Source: /home/dent/web/src
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 Source: /home/dent/web/src -earth.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 $ bin/build -a
blog comments powered by Disqus |
|
|
|
|
|
|
|