Continuing on my journey of struggles w/ doing a little more complicated HTML::Template work, I find myself with this problem...
I have a page that displays a table of data. The user is given the option of selecting which columns of data will be displayed.
I'm trying to keep my code as neat as possible. I know I could just have a VAR in the template, and do a ton of if statements in the template file, to see if each column was selected, but I would rather do it as a LOOP. It will save my template file at least 40 lines of code, and keep things a lot neater.
Simple example/explanation:
A table has 5 optional columns via checkboxes. The user checks off the boxes, clicks submit, then the appropriate columns are displayed when the page is generated.
If the user selects columns 2, 4 and 5, the page is generate showing a table with only those 3 columns.
Earlier in the file, I store the selections in an array.
So...
my @selections = (2, 4, 5);
Column names:
1 = column number 1
2 = column number 2
3 = column number 3
4 = column number 4
5 = column number 5
could someone suggest some code as how I could create the appropriate variable to send to the HTML Template so that it can loop through them?
ie. how would you store the selected column header's names into $rows, so that the following would work?
my $template=HTML::Template->new(filename=>"tmpl/bottom.tmpl");
$template->param(ROWS => $rows);
print $template->output;
Any help would be GREATLY appreciated!
*worships the Perl Monks*
Stenyj
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.