Greetings fellow monks,
I've been using HTML::Template in combination with CGI::Application for a while now with much success and joy. However, I've recently come into a situation where I need some advice. I have a series of templates being used by a Web application which use HTML::Template's TMPL_INCLUDE tag to insert additional templates. I'm quickly running into a situation where I'm going to need to define the name of the included template in the Perl code of application module, not the template tag. For example, here's what I have right now:
<TMPL_INCLUDE name="page_header_type_1.tmpl"> <P>Welcome to this page, <TMPL_VAR name=firstname>.</P> <TMPL_INCLUDE name="page_footer_type_1.tmpl">
And of course, the Perl code inside the CGI::Application-type screen handler subroutine looks something like this:
my $self = shift; my $tmpl_obj = $self->load_tmpl('generic_page.tmpl', die_on_bad_params => 1, filter => \&tmpl_filter); $tmpl_obj->param( firstname => 'Bob' ); return $tmpl_obj->output;
The problem is that now I need to have several "page_handler_type_*.tmpl" files, and I'll only know which one to include at run-time. What I'd really love to do is embed via TMPL_VAR the name of the to be included template file for the header inside the TMPL_INCLUDE tag, much like how you can embed TMPL_VAR tags inside any other HTML tag:
<TMPL_INCLUDE name="<TMPL_VAR name="includeheadername">">Then I could just add "includeheadername" to the list of stuff sent to $tmpl_obj->param(), but that's not allowed. I could also construct the final page as page parts generated by multiple "$tmpl_obj"s inside the screen handler subroutine, but that starts to defeat the whole purpose of using HTML::Template in the first place.
Any thoughts, suggestions, comments about how best to solve this dilema?
-gryphon
code('Perl') || die;
In reply to Dynamic TMPL_INCLUDE in HTML::Template by gryphon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |