Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hello Monks,

I'm having some trouble with HTML::Template. After following the tutorial here, I have the following code:

HTML:
<TABLE BORDER="1"> <TR><TD>Transaction</TD><TD>DATE</TD><TD>Type</TD><TD>Amount</TD> +<TD>Ending Balance</TD></TR> <TMPL_LOOP NAME="TRANSACTIONS"> <TR><TD>Transaction:</TD> <TD><TMPL_VAR NAME="Date"></TD> <TD><TMPL_VAR NAME="Type"></TD> <TD><TMPL_VAR NAME="Amount"></TD> <TD><TMPL_VAR NAME="Ending_Balance"></TD></TR> </TMPL_LOOP> </TABLE>

and my Perl code:
my $template = HTML::Template->new( filename => 'atm_choose.tmpl', die +_on_bad_params => 0 ); my @LINES; while (<DATA>) { chomp; push @LINES, $_; } my $split; for (@LINES) { my @row = split ('&', $_); push @{$split}, $_; } $template->param(TRANSACTIONS => $split); print header, $template->output; __DATA__ 10/02/2013 & closing balance & 0 & 1000 11/02/2013 & debit & 100 & 900 12/02/2013 & credit & 1000 & 1900

I'm currently getting the table correctly formatted, but it is entirely empty. I *THINK* I'm giving HTML::Template the correct variable.
thank you,

edit

I was able to get the table as expected, but this doesn't seem like good practice (even useful as it doesn't allow for more information to be used...). However, I am unable to get this to work using a foreach / for loop. any pointers please?

while (<DATA>) { chomp; push @LINES, $_; } my @split; for (@LINES) { my @row = split ('&', $_); push @split, \@row; } $template->param(TRANSACTIONS => [{Date => $split[0][0], Type => $spli +t[0][1], Amount => $split[0][2], Ending_Balance => $split[0][3]}, {Date => $split[1][0], Type => $split[1][1], Amount +=> $split[1][2], Ending_Balance => $split[1][3]}, {Date => $split[2][0], Type => $split[2][1], Amount +=> $split[2][2], Ending_Balance => $split[2][3]} ]);

Thank you! </p<

J -

In reply to Using HTML Template to fill a 2-dimensional table by jms53

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (10)
    As of 2014-12-28 16:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (182 votes), past polls