[htmltmpl] [Question] Clearing <TMPL_LOOP> content after first pass
Brought to you by:
samtregar
From: C H. <hag...@ep...> - 2004-05-21 16:36:24
|
I'm struggling with a <TMP_LOOP> problem ... Using a subroutine call: if ( $q->param('action') eq 'one') { CallSubroutine('Red'); } I send a "select" call to a MySql table. The subroutine call includes a value that determines what records are returned. I "grab" what the select call returns using: my $res = $sth->fetchall_arrayref({}); ................... assign it to a parameter: $q->param(res => $res); ................... call the template using "associate" my $template = HTML::Template->new( filename => 'template_filename.tmpl', associate => $q, ); .................. write the template content to a file open (FILE,">$filename") or die "no $filname!\n"; $template->output(print_to => *FILE); close(FILE); .................. the template looks like: <TMPL_LOOP res> All kinds of HTML stuff here, including <TMPL_VAR NAME=whatever> values </TMPL_LOOP> ........................ The above works fine. The problem I'm having is when I call the subroutine twice - each time sending a different value: if ( $q->param('action') eq 'two') { CallSubroutine('Red'); CallSubroutine('Blue'); } The output is written to the correct two files, *but* the content of the files is identical, and always matches the content of the first iteration of the subroutine: if ( $q->param('action') eq 'two') { CallSubroutine('Red'); CallSubroutine('Blue'); } produces two identical files with the "Red" content if ( $q->param('action') eq 'two') { CallSubroutine('Blue'); CallSubroutine('Red'); } produces two identical files with the "Blue" content. It appears that the template "storing" the first loop content, and not letting it go when the subroutine is called the second time. I'm an H::T newbie ... maybe there's something obvious I'm missing? Carl Hagstrom |