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


in reply to HTML::Template's watchful eye

I'm guessing the easiest work-around would be to add to your template include path so that even templates that don't actually get used can be found, like:

my $template = HTML::Template->new( filename => 'file.tmpl', path => [ '/path/to/templates', '/alternate/path' ] );

I've become increasingly unhappy with HTML::Template lately, largely due to the inability to do a construct like

<tmpl_include name="<tmpl_var name='foo'>">
which is another form of what you seem to be looking for. As far as I know, the only way to accomplish something like this is to use the "filter" option, like:
my $tmpl = HTML::Template->new( 'filename' => "foo.tmpl", 'filter' => sub { my $text_ref = shift; $$text_ref =~ s/special include tag/the actual include file ta +g/; } );


Xaositect - Whitepages.com

Replies are listed 'Best First'.
Re^2: HTML::Template's watchful eye
by radiantmatrix (Parson) on Jun 24, 2005 at 20:09 UTC
    I'd never considered this as a problem, as I accomplish the same thing with a construct like:
    my $master = HTML::Template->new(filename=>'master.tmpl'); ### BLAH, BLAH ### my $sub_tmpl = HTML::Template->new(filename=>$foo); $sub_tmpl->param('variable'=>'value'); $master->param('include_foo' => $sub_tmpl->output); __END__ The template like: <tmpl_var name='include_foo' default=''>
    So far I haven't encountered a case where this approach isn't just peachy, but of course YMMV.

    Yoda would agree with Perl design: there is no try{}

      Ooooh... That hadn't occured to me. I like it. ++!


      Xaositect - Whitepages.com
      A reply falls below the community's threshold of quality. You may see it by logging in.
Re^2: HTML::Template's watchful eye
by jeyroz (Monk) on Jun 24, 2005 at 19:46 UTC

    Well I certainly love the simplicity of H::T but I agree with your comment. Your example was one of my very first frustrations.

    Other than my rather insignificant gripes, I enjoy using the tool.

    author => jeyroz