in reply to HTATR II: HTML table generation via DWIM tree rewriting
I will agree that i like your template better when it comes to alternating colors. I probably should have handled the color picking inside the Perl code and not the template, but this is a trivial move. As it stands, i am really starting to like the Template mini-language.package Simple::Class; use strict; use warnings; use Class::MethodMaker new_hash_init => 'new', get_set => [qw(age name weight)], ; sub load_data { return [ map { Simple::Class->new({ name => $_, age => int(rand(50))+20, weight => int(rand(150))+20, }) } qw(bob bill brian babette bobo bix) ]; } package main; use strict; use warnings; use Data::Dumper; use Template; my $template = Template->new; $template->process(\*DATA,{people => Simple::Class::load_data}) || die $template->error; __DATA__ [% colors = ['white','gray'] %] <table> <tr><th>name</th><th>age</th><th>weight</th></tr> [% FOREACH person = people %] [% PROCESS row person = person %] [% END %] </table> [% BLOCK row %] [% color = colors.shift %] <tr> <td bgcolor="[% color %]">[% person.name %]</td> <td bgcolor="[% color %]">[% person.age %]</td> <td bgcolor="[% color %]">[% person.weight %]</td> </tr> [% colors.push(color) %] [% END %]
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Different Web Shops Need Different Tools
by princepawn (Parson) on Oct 30, 2003 at 15:36 UTC | |
by jeffa (Bishop) on Oct 30, 2003 at 16:21 UTC | |
by princepawn (Parson) on Oct 30, 2003 at 17:57 UTC | |
|
Re: Re: HTATR II: HTML table generation via DWIM tree rewriting
by cbraga (Pilgrim) on Oct 30, 2003 at 16:54 UTC | |
by jeffa (Bishop) on Oct 30, 2003 at 18:31 UTC |