Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Two questions about HTML::Template

by cees (Curate)
on Jun 23, 2006 at 15:31 UTC ( #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; );


Comment on Re: Two questions about HTML::Template
Download Code
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
Node Status?
node history
Node Type: note [id://557229]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2014-09-20 12:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (159 votes), past polls