I am with Bird on this one gryphon (although i do really like fruiture's suggestion). Here is why - right now you have two colors for two kinds of rows, but what happens when someone in charge decides that they want three colors, or four or five? __ODD__ isn't going to cut it anymore. By utilizing the modulus (%) operator, you can easily loop through a list of 'classes'. Consider this (and replace the single quotes with double quotes if you are running this on Win32 system):
perl -le '@a = a..d; print $a[$i++ % @a] for 0..15'
Couple this with a map and you can add a different class for every row of data. Now, i don't agree with storing the style sheet info inside the script, after all, you want the others in your group to maintain that part. Having said all of that, here is my example:
use strict; use HTML::Template; my $data = do {local $/; <DATA>}; my $tmpl = HTML::Template->new(scalarref => \$data); my $rows = [ { col1 => 'Graham Chapman', col2 => 'John Cleese' }, { col1 => 'Terry Gilliam', col2 => 'Eric Idle' }, { col1 => 'Terry Jones ', col2 => 'Michael Palin' }, { col1 => 'Terry Jones ', col2 => 'Michael Palin' }, { col1 => 'Terry Gilliam', col2 => 'Eric Idle' }, ]; my $i = 0; my @class = qw(one two three); $tmpl->param( rows => [ map { { %$_, class => $class[$i++ % @class] } } @$rows ], ); print $tmpl->output; __DATA__ <style type="text/css"> <!-- table { border-spacing: 0px; } td { padding: 3px; } td.one { background-color: #c0c0c0; } td.three { background-color: #e0e0e0; } td.two { background-color: #d0d0d0; } --> </style> <table> <tmpl_loop rows> <tr> <td class="<tmpl_var class>"> <tmpl_var col1> </td> <td class="<tmpl_var class>"> <tmpl_var col2> </td> <tr> </tmpl_loop> </table>
So, the code is a little more complex, but not terribly more and definitely at the expense of making the template less complex. I am sure the others in your group will appreciate it. :)

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)

In reply to (jeffa) Re: Loop Context Style with HTML::Template by jeffa
in thread Loop Context Style with HTML::Template by gryphon

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.