(I like writing my TMPLs in upper case and my HTML in lower case to tell them apart visually - no other reason).<table bgcolor=#66aaff border=2 bordercolor=#ffffff cellspacing=0 cell +padding=6> <TMPL_LOOP RESULTS> <tr> <td> <TMPL_VAR CHK> </td> <td> <TMPL_VAR NAME> </td> <td> <TMPL_VAR COST> </td> <td> <TMPL_VAR NUMBER> </td> <td> <TMPL_VAR TXT> </td> </tr> </TMPL_LOOP> </table>
Simple, really. The marginally tricky bit is getting the data into the right form to go into the template. The single line $results_tmpl->param(results => \@results); is doing duty for a lot of lines like#!/usr/bin/perl -w use strict; use CGI qw(:standard); use HTML::Template; # my guess about what your data structure might be: my %information = ( txt_foo => ['chk_foo','name_foo','cost_foo','number_foo'], txt_bar => ['chk_bar','name_bar','cost_bar','number_bar'], txt_baz => ['chk_baz','name_baz','cost_baz','number_baz'], ); # initialise the template and other vars: my $results_tmpl = HTML::Template->new(filename => 'results.tmpl'); my @results; # populate @results with the data from %information: for (keys %information) { my %row_data; $row_data{'txt'} = $_; $row_data{'chk'} = $information{$_}[0]; $row_data{'name'} = $information{$_}[1]; $row_data{'cost'} = $information{$_}[2]; $row_data{'number'} = $information{$_}[3]; push @results, \%row_data; } # drop the info into the template: $results_tmpl->param(results => \@results); # print the page: print header, start_html, $results_tmpl->output(), end_html;
But obviously if you had to write it all out by hand, you might as well not be using the template at all. What I'm saying is that the code for populating the template will work, but it may take a bit of effort to get your head around it (it did mine). But you said you wanted to get it on your hands...$results_tmpl->param( results => ( txt => 'txt_foo', chk => 'chk_foo', ......
#!/usr/bin/perl -w use strict; module library use CGI qw(:standard); use CGI::tab; my %information = ( txt_foo => ['chk_foo','name_foo','cost_foo','number_foo'], txt_bar => ['chk_bar','name_bar','cost_bar','number_bar'], txt_baz => ['chk_baz','name_baz','cost_baz','number_baz'], ); print header, start_html, start_tabs(75,150,225,300); for my $key (keys %information) { print $key,t; print $_,t for @{ $information{$key} }; } print end_tabs, end_html;
In reply to Re: Re: Yet Another Stupid CGI Question
by George_Sherston
in thread Yet Another Stupid CGI Question
by chaoticset
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |