[Templates] Deciding which template to execute at runtime

Stuart Johnston saj at thecommune.net
Sat Oct 6 17:06:54 BST 2007


Anthony Gardner wrote:
> I've looked through the docs, more than a year of mail archives and 
> googled but was unable to find an answer. Either looking in the wrong 
> place or not hard enough.
> 
> At present, we have a standard set of templates but in the future, we 
> may need to deliver the same data but in a different style. This will be 
> set using a query string parameter.
> 
> As the $tt is created as a singleton one / process (mod_perl) and the 
> paths defined once, can someone tell me of a simple way round this.
> 
> I've thought of just having a generic template entry point and then 
> calling the desired  starting template based on a simple IF ELSE  but 
> hopefully there's a TT configuration way.
> 
> I'm sure this has been asked before but just can;t find the answer :(

The main idea is to change the include_path with each request.  This way 
your 'styled' folder only needs to include template files that are 
actually changed, it can fall back to the default if not found.  Mihai 
suggests one way to do this using a sub reference.  Another way is to 
pass an array ref to include_path.  Hang on to the reference and you can 
modify it before each process.

http://www.template-toolkit.org/pipermail/templates/2000-August/000157.html



More information about the templates mailing list