Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation


by MZSanford (Curate)
on Oct 18, 2001 at 15:54 UTC ( #119653=note: print w/replies, xml ) Need Help??

in reply to Learning syntax for HTML::Template TMPL_IF

O'Reilly's "CGI Programming with Perl" covers it a bit, but i would suggest the HTML::Template docs for an online version.
i had a memory leak once, and it ruined my favorite shirt.

Replies are listed 'Best First'.
by Anonymous Monk on Oct 18, 2001 at 16:08 UTC
    Anybody knows how to use a in a , where "name" is not in "loop", but is a variable from elseware!!
      It should say use a var_name in a var_loop, where "name" is not in "loop", but is a variable from elseware
        If I understand your question correctly, you're defining an HTML::Template parameter outside a loop and then trying to use it within a TMPL_LOOP. I.e., the code looks something like this:
        my $template = new HTML::Template ( filename => "file.tmpl" ); $template->param( outside_of_loop => "foo", the_loop => [ { inside_of_loop => "bar" }, { inside_of_loop => "baz" } ] );
        And your template looks like this:
        Outside: <TMPL_VAR NAME=outside_of_loop> <TMPL_LOOP NAME=the_loop> Inside: <TMPL_VAR NAME=outside_of_loop> <TMPL_VAR NAME=inside_of_l +oop> </TMPL_LOOP>
        You're expecting this output:
        Outside: foo Inside: foo bar Inside: foo baz
        But you're getting this instead:
        Outside: foo Inside: bar Inside: baz
        The problem is that TMPL_VARs defined outside of a loop don't show up within the loop. The solution is to set global_vars => 1 when you create the HTML::Template object. E.g.:
        my $template = new HTML::Template ( filename => "file.tmpl", global_vars => 1 );


        Read up in the documentation about setting your variables global.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://119653]
[LanX]: ... treid to make smalltalk and felt like Sheldon.
erix looks up Sheldon ...
[erix]: ah. well, that must feel nice, no? ;)
[erix]: not the best way to make friends, though (I suppose)
LanX Fun with Flags anyone?

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2018-03-22 18:49 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (283 votes). Check out past polls.