http://qs321.pair.com?node_id=557229


in reply to Two questions about HTML::Template

in HTML::Template, the includes are processed when the template is parsed, and the variables and if statements are interpolated when the template is processed. So your includes all have to exist, and they will all be loaded and parsed regardless of any if statements around them.

When you want to change the template that is included based on a decision in the code, I often find it easier to change the include path that HTML::Template uses, and then use the same include file name in your template. By changing the include path. HTML::Template will look in a different place for the include file when the template is parsed. Here is some psuedo code to illustrate it:

my @path; if ($foo) { push @path, '/foo'; } else { push @path, '/bar'; } push @path, '/standard_templates'; my $template = HTML::Template->new( filename => 'file.tmpl', path => \@path; );

Replies are listed 'Best First'.
Re^2: Two questions about HTML::Template
by Cody Pendant (Prior) on Jun 23, 2006 at 21:17 UTC
    That makes the most sense to me, I'll use that, thanks cees.


    ($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
    =~y~b-v~a-z~s; print
Re^2: Two questions about HTML::Template
by bradcathey (Prior) on Jun 10, 2007 at 00:49 UTC

    I use CGI::Application and for the edification of like-minded folks, here's what I came up with (basically an array of paths, the 2nd one used for site-specific tmpls):

    #instance script passes in PARAMS which is also the directory with sit +e specific .tmpls my $site = $self->param('name_of_site'); $self->param('project' => '/usr/home/somedomain/ecomm/'); $self->param('tmpl_path' => [ $self->param('project_').'tmpls/', $self->param('project_path').'tmpls/ +includes/'.$self->param('site') ]);


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot