Hello, I am trying to perform an inner/outer loop with global_vars set, as shown in the H:T man page:
# test.tmpl - from the man page ---------- <TMPL_LOOP OUTER_LOOP> OUTER: <TMPL_VAR OUTER_VAR> <TMPL_LOOP INNER_LOOP> INNER: <TMPL_VAR INNER_VAR> INSIDE OUT: <TMPL_VAR OUTER_VAR> </TMPL_LOOP> </TMPL_LOOP> # test.pl ------------------ #!/usr/bin/perl -w use strict; use HTML::Template 2.9; my $template = HTML::Template->new( filename => 'test.tmpl', die_on_bad_params => 1, loop_context_vars => 1, global_vars => 1, ); $template->param( OUTER_LOOP => [ { OUTER_VAR => 'I AM THE OUTER VAR' }, { INNER_LOOP => [ { INNER_VAR => 'I AM THE INNER VAR' }, ] }, ], ); print $template->output; This processes, but outputs: ---- OUTER: I AM THE OUTER VAR OUTER: INNER: I AM THE INNER VAR INSIDE OUT: ---- I suppose thats somewhat close to what I would expect, except that the outer_var is not available inside the inner_loop. I was also a little bit surprised that the inner_loop was iterated over by the outer loop, resulting in two 'OUTER:' outputs - but when I think about it I suppose that could be considered correct, although slightly odd IMO. So I tweaked my code to something simpler that seemed like it should work: #!/usr/bin/perl -w use strict; use HTML::Template 2.9; $template = HTML::Template->new( filename => 'test.tmpl', die_on_bad_params => 1, loop_context_vars => 1, global_vars => 1, ); $template->param( OUTER_LOOP => [ { OUTER_VAR => 'I AM THE OUTER VAR' } ], INNER_LOOP => [ { INNER_VAR => 'I AM THE INNER VAR' } ], ); print $template->output; Just two simple loops for use in the template. But this one dies with: HTML::Template : Attempt to set nonexistent parameter 'inner_loop' - this parameter name doesn't match any declarations in the template file : (die_on_bad_params => 1) at test.pl line 42 I'm surprised I cannot get the man page example to work correctly. Does anyone have any ideas on this? Thanks, Alex P.S - My next step involves something like this: <TMPL_LOOP OUTER_LOOP> <TMPL_LOOP INNER_LOOP> INNER: <TMPL_VAR INNER_VAR> INSIDE OUT: <TMPL_VAR OUTER_VAR> </TMPL_LOOP> </TMPL_LOOP> where all the outer_loop vars are actually used in the inner_loop, and never used in the outer_loop. This specific functionality is fixed in version 2.9 according to the changelog: http://search.cpan.org/src/SAMTREGAR/HTML-Template-2.9/Changes - Bug Fix: Long-standing bug where variables set in a loop weren't available inside inner loops under global_vars if the variable wasn't actually used in the outer loop. (Thanks to Richard Fein for help debugging the fix.) ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ Html-template-users mailing list Html-template-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/html-template-users