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

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Html-template-users mailing list
Html-template-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/html-template-users

Reply via email to