Template Toolkit: how to generate static HTML on any path

A Tech article with View Comments posted 4 April 2007.
Tags: , ,

My company generates our website using Template Toolkit’s ttree tool. We want our site to be built with absolute paths in the HTML, so we need to be able to accomodate that with file:// URLs when we test it. We use code like this:

The script to invoke ttree in our testing environment:

#!/bin/bash
cd `dirname $0`
rm -r ./out_test/*
ttree -a --relative --pre_process=./lib/config.test \\
         --pre_process=./lib/config.common \\
         --define basedir=`pwd` \\
         -f ./lib/ttree_test.cfg

In lib/config.test:

[% root = 'file://' _ basedir _ '/out_test' %]

In lib/config.deploy (when we build for production):

[% root = 'http://www.ideaworks.com/' %]

This way, rather than hard-coding the testing path in lib/config.test, it Just WorksTM.

You might also enjoy:

  1. Dynamic CSS/JS/HTML in Template Toolkit wrappers
  2. My first CPAN acknowledgement
  3. Debugging long-running perl programs in Debian
  4. Installing BackupPC on OpenWRT
  5. Extracting the next 7 days from phpiCalendar to simple HTML

    blog comments powered by Disqus