Here's some sample code that doesn't work.
My main problem is that I don't understand what data type is suppose to be send to the TMPL_LOOP in the template, and don't understand how to create & modify the data type before sending it...
At least, I'm 99% sure that's my problem.

my @checkedOptions = qw(team rank land networth strat updated mari +ne fighter bomber panzer hl seal pds offPts defPts turns); my @tableHeaders; foreach my $i (@checkedOptions) { push @tableHeader, $i; }

That places the selected options into an array. then this:
my $tableHeader = tableHeader(@tableHeader);

is used to send that array to a subroutine, that I would like to create an appropriate data type for the TMPL_LOOP and then store the appropriate data to it.

Then subroutine I was attempting was this:
sub tableHeader { my @tableHeader = $_[0]; my $rows; my %tempHash; foreach my $i (@tableHeader) { if ($i eq 'nw') { push @{$rows}, {columnHeader => 'Networth'} } elsif ($i eq 'hl') { push @{$rows}, {columnHeader => 'Heavy Lasers'} } elsif ($i eq 'offPts') { push @{$rows}, {columnHeader => 'Off. Pts'} } elsif ($i eq 'defPts') { push @{$rows}, {columnHeader => 'Def. Pts'} } elsif ($i eq 'last_updated') { push @{$rows}, {columnHeader => 'Updated'} } else { $tempHash{'columnHeader'} = capitalize($i); push @{$rows}, {columnHeader => $i} } } return $rows; }

I was then hoping to juse use the following in a HTML::Template file to create the appropriate column headers:
<TMPL_LOOP NAME=tableHeader> <td align=center valign=middle><B>&nbsp;<TMPL_VAR NAME=columnH +eader>&nbsp;</B><TD> </TMPL_LOOP>
Basically I was hoping to send an array of hashes (each hash only containing 'columnHeader => columnName') to the template, and then to loop through each of them to pull the column names that were selected.

I tried disecting the code I use to pull data from a table and send it to the template, but obviously went about it the wrong way ;-P

Any help is greatly appreciated.

If I wasn't clear in explaining what I was trying to do, please let me know and I'll gladly attempt to re-explain in a more clear manner.

I'm still relatively new to some of the more complex (at least, more complex for me) parts of HTML::Template, and am trying to do the coding right the first time, rather then having to recode everything in the future :-)


Thanks again!


Steny

20040530 Edit by Corion: Fixed formatting, moved stuff into CODE tags


In reply to Re: Re: Sending data for LOOP in HTML::Template by Steny
in thread Sending data for LOOP in HTML::Template by Steny

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.