Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Setting HTML::Template options after new()

by Cody Fendant (Friar)
on Apr 21, 2010 at 01:07 UTC ( #835924=perlquestion: print w/replies, xml ) Need Help??
Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:

I've got some code where I create an HTML::Template object at the top, and then later on, may want to use the options loop_context_vars or global_vars depending on conditionals.

There's nothing in the POD about doing it that, way. But by dumping the HTML::Template object, I could see that these could be accessed like this:

$t->{options}->{loop_context_vars} = 1; $t->{options}->{global_vars} = 1;
interestingly, it works for loop_context_vars but not global_vars

Is there a reason for this? Can I do it a different way? Or alternatively, should I just turn them both on, even if they're not needed, and not try and do it conditionally? I was just being naturally conservative about turning on features which wouldn't be needed, that's all. Is there any kind of speed or performance implication to using these features?

Example code:

use HTML::Template; $t = HTML::Template->new( filehandle => *DATA, die_on_bad_params => 0 ); $t->{options}->{loop_context_vars} = 1; # turned on so I can use <tmpl_if name="__first__"> $t->{options}->{global_vars} = 1; # turned on so I can have a global var appear inside a loop $t->param( foo => [ { baz => 1 }, { baz => 2 }, { baz => 3 } ] ); # some loop data $t->param( bar => 'global var!' ); # a global variable print $t->output(); __DATA__ <tmpl_loop name="foo"> <tmpl_var name="bar"> <!-- this doesn't appear --> <tmpl_if name="__first__"> first! </tmpl_if> * <tmpl_var name="baz"> </tmpl_loop>

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://835924]
Approved by toolic
Front-paged by ww
[erix]: I recognise the makings of a fine argument
[LanX]: lanx wonders ... how likely is it to talk >95% BS without intention?
[erix]: "gigantic amounts of data" is also not SQLite (imho)
talexb wonders why sqlite2 was deprecated in favour of sqlite3.
[erix]: looks like a fork, rather, no?
LanX /me /me
[erix]: /hehehe
[marto]: LanX yesterday I found out about Gish gallop tactic

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (13)
As of 2017-07-28 15:38 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (431 votes). Check out past polls.