Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: IF in a loop using HTML::Template

by Anonymous Monk
on Mar 20, 2013 at 19:13 UTC ( [id://1024596]=note: print w/replies, xml ) Need Help??


in reply to IF in a loop using HTML::Template

I dont understand why I am getting the error since I have the TMPL_IF NAME="test"> tag in the .tmpl file.

Maybe you're loading the wrong template, who knows, so turn on debugging, and figure it out

#!/usr/bin/perl -- use strict; use warnings; use HTML::Template; my $template = HTML::Template->new( die_on_bad_params => 1, #~ scalarref => \'<tmpl_if spectacles>glasses<tmpl_else>stars</tmp +l_if> ', scalarref => \'<tmpl_if name="spectacles">glasses<tmpl_else>stars< +/tmpl_if> ', debug => 1, #~ stack_debug => 1, ); $template->param( spectacles => 0 ); print $template->output; $template->param( spectacles => 1 ); print $template->output; print "\n"; __END__ ### HTML::Template Debug ### In _parse: ### HTML::Template Debug ### /fake/path/for/non/file/template : line 1 + : TMPL_IF spectacles start ### HTML::Template Debug ### /fake/path/for/non/file/template : line 1 + : ELSE ### HTML::Template Debug ### /fake/path/for/non/file/template : line 1 + : /TMPL_IF end ### HTML::Template Debug ### In output ### HTML::Template Debug ### In output stars glasses

See Basic debugging checklist, brian's Guide to Solving Any Perl Problem

Replies are listed 'Best First'.
Re^2: IF in a loop using HTML::Template
by Anonymous Monk on Mar 20, 2013 at 19:20 UTC
    I don't understand your point, definitely not loading the wrong template, using CGI::Application for this as well. You can see on the code that "test" has been declared in the .tmpl and called in the perl file. The template gets called as:
    my $template = $self->load_tmpl('mytemp.tmpl');

      I don't understand your point,

      Turn on debugging , and figure out where the problem is. The code you posted is not complete, I can't run it and figure it out for you.

        OK here is something that illustrate my issue:
        #!/usr/bin/perl use strict; use warnings; use HTML::Template; my $t=HTML::Template->new(filename=>'temp.tmpl'); my @foo=({bar=>1,baz=>2},{bar=>3,baz=>4}); $t->param(foo=>\@foo); my $test = 1; my $message = 'Yes there is' if $test; $t->param(TEST => $message ); print $t->output;
        and . tmpl file
        <tmpl_loop name="foo"> <tmpl_var name="bar"> <tmpl_var name="baz"> <TMPL_IF NAME="TEST"></TMPL_IF> </tmpl_loop>
        I hope someone can help!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-19 21:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found