Molt has asked for the wisdom of the Perl Monks concerning the following question:
I'm currently working on a web application using Template Toolkit, but now I'm experiencing difficulties trying to work out the nicest way to allow dynamic includes.
What I'm trying to do is have a template including other templates dynamically based on either the status of a variable, or the result of a function, so that the following could be made to work. Please note I do know that the 'header' and 'body' in the includes are taken as literals, it's this I'm trying to get round here.
As part of program:
$template->process( 'toplevel.html', { title => 'Hello, World', header => 'current_header.html', body => 'welcome_page.html' } };
As toplevel.html
<html> <head> <title>[% title %]</title> </head> <body> [% INCLUDE header %] <!-- To include current_header.html, somehow--> [% INCLUDE body %] <!-- To include welcome_page.html --> </body> </html>
The aim of this is to allow me to associate new actions to page contents without a change either to the basic code, or to the top-level page templates.
I could code up a plugin to do this, but fear reinventing wheels. Any hints?