Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Two questions about HTML::Template

by cees (Curate)
on Jun 23, 2006 at 15:31 UTC ( [id://557229]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://557229]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2025-02-07 15:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (94 votes). Check out past polls.