[htmltmpl] Probable bug in TMPL_LOOP
Brought to you by:
samtregar
From: Boris L. <bor...@gm...> - 2012-05-29 12:31:01
|
Description: TMPL_VAR used for same variable both in the loop and outside of the loop, is empty when used within the loop. Example: a table of account transactions. In PERL we fill the template with this code: my $acct_rec = HTML::Template->new(filename => $args{template}); $acct_rec->param(ACCOUNTID => $args{accountid}); my @loop_data = (); ... $sth->execute(@args{qw/accountid/}) or die "SQL Error: $DBI::errstr\n"; ## gets transactions from db while ($row = $sth->fetchrow_hashref) { my %tbl_row; # get a fresh hash for the row data $tbl_row{IS_CHARGE} = ($$row{trxtype} eq 'C') ? 1 : 0; $tbl_row{TRXID} = $$row{trxid}; $tbl_row{TRXDATE} = $$row{trxdate}; $tbl_row{UNAME} = $$row{uname}; $tbl_row{SNAME} = $$row{sname}; $tbl_row{QUANTITY} = $$row{quantity}; $tbl_row{PRICE} = $$row{price}; $tbl_row{AMOUNT} = $$row{amount}; push(@loop_data, \%tbl_row); } $acct_rec->param(TRX_LOOP => \@loop_data); -------------------------------------------------------------- Html template file <table border=0 cellspacing=2 cellpadding=2 width:100%> <tr style='color: #000000; background-color: #BBBBBB; font-size: 10pt'> <td>Account ID</td> <!-- THIS ONE WORKS --> <td><TMPL_VAR NAME="ACCOUNTID"></td> <!-- EOC --> </tr> <tr style='color: #000000; background-color: #BBBBBB; font-size: 10pt'> <th>Date</th> <th>User</th> <th>Charge/Payment</th> <th>Quantity</th> <th>Price</th> <th>Amount</th> <th>Comment</th> <th>Cancel</th> </tr> <TMPL_LOOP NAME="TRX_LOOP"> <TMPL_IF IS_CHARGE> <tr style='color: #000000; background-color: #FFFFCC; font-size: 10pt'> <TMPL_ELSE> <tr style='color: #000000; background-color: #CCFFCC; font-size: 10pt'> </TMPL_IF> <!-- THIS ONE DOESN'T WORK --> <td align=left><TMPL_VAR NAME="ACCOUNTID"></td> <!-- EOC --> <td align=left><TMPL_VAR NAME="TRXDATE"></td> <td align=left><TMPL_VAR NAME="UNAME"></td> <td align=left><TMPL_VAR NAME="SNAME"></td> <td align=center><TMPL_VAR NAME="QUANTITY"></td> <td align=right><TMPL_VAR NAME="PRICE"></td> <td align=right><TMPL_VAR NAME="AMOUNT"></td> <td align=left><TMPL_VAR NAME="COMMENT"></td> </tr> </TMPL_LOOP> </table> ---------------------------------------------- i.e. ACCOUNTID works outside the loop, inside the loop it stays empty Ubuntu 11/nginx + plack/perl 5.2.14/HTML::Template Module Version: 2.91 |