Template Toolkit: how to generate static HTML on any path
Wednesday, April 4th, 2007My 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.


