Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: A question regarding HTML::Template, tables, and loops

by samtregar (Abbot)
on Sep 02, 2002 at 02:28 UTC ( #194505=note: print w/replies, xml ) Need Help??

in reply to A question regarding HTML::Template, tables, and loops

There are any number of ways to solve this problem with HTML::Template, but here's how I'd do it. Here's the script:

use HTML::Template; my $template = HTML::Template->new(filename => "test.tmpl"); my @data = (1 .. 30); my $items_per_row = 5; my $x = 0; my @loop; foreach (@data) { my %row = ( data => $_ ); $row{break} = 1 unless $x % $items_per_row or $x == 0; push @loop, \%row; $x++; } $template->param(loop => \@loop); print $template->output();

And the corresponding template:

<table> <tr> <tmpl_loop loop> <tmpl_if break></tr><tr></tmpl_if> <td><tmpl_var data></td> </tmpl_loop> </tr> </table>

Does that help?


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://194505]
[Corion]: margeas: I'll look at renaming you ;)
[markong]: ahah thanks Corion :)
[Eily]: Discipulus usually it's while testing that you want the full logs :)
[Eily]: anyway, maybe you can ignore STDERR ? (I'm not sure about @CARP_NOT, it looks like it only changes the place the error comes from)
[markong]: " Perl: the Markov chain saw" :D aha
[Discipulus]: thanks 1nickt but seems i'm not able to use it correctly...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2018-01-22 11:23 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (233 votes). Check out past polls.