Welcome!
Thanks for visiting. If you found this information interesting or useful (or you think I'm dead wrong about something) I'd like to invite you to leave a comment on this post. You can also
subscribe to my RSS feed or sign up for email updates on the right-hand side of the page.
If you Digg what you StumbleUpon, find my writing del.icio.us, or are one of the Technorati, you know what to do:
Dynamic CSS/JS/HTML in Template Toolkit wrappers
I’ve been asked about this a few times on #tt, so I thought I’d provide it for future Googlers. If you’re looking to optionally include certain files in a Template Toolkit wrapper, it’s very easy. You just provide the file names as a parameter to the WRAPPER call.
First, the wrapper file itself, wrapper.tt:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>[% title %]</title>
<body>
[% IF includes %]
<div id="sidebar">
[% FOREACH include_file = includes %]
[% INCLUDE $include_file %]
[% END %]
</div>
<div id="content">
[% ELSE %]
<div id="wide_content">
[% END %]
[% content %]</div>
</body>
</html>
And then you call the file like this:
[% WRAPPER wrapper.tt
title = 'My Title'
includes = [
'includedfile1.tt',
'includedfile2.tt'
]
%]
<h1>Content for middle</h1>
[% END %]
It’s pretty straightforward to adapt this to CSS or JS files, or whatever you need to customize in the wrapper.
Related posts:
- Template Toolkit: how to generate static HTML on any path My company generates our website using Template Toolkit's ttree tool....
- Extracting the next 7 days from phpiCalendar to simple HTML Edit: Newer versions of phpiCalendar give you this feature without...
- Podcasts from Ravi Zacharias Jennifer and I participated in a small group at Truman...
- Using next_successor with Graph::Traversal I recently needed to do a graph traversal using the...
- Remove Horizon (Dynix) automatic refresh I find the automatic refresh on my seminary library's catalog...


November 10th, 2008 04:42
As a “future Googler”, thank you.