I would definitely go with option 3, but why not take it one step further? Rename your "__ODD__" template variable to something like "class", then store the full class name instead of just a "1" or "" in that variable. Your HTML then looks like this...
<STYLE type="text/css"><!-- TD.loop1 { background-color: #c0c0c0; } TD.loop { background-color: #e0e0e0; } --></style> <TABLE border=0 cellspacing=0 cellpadding=3> <TMPL_LOOP name="some_loop"> <TR> <TD class=<TMPL_VAR name="class">> <TMPL_VAR name="content_column_1"> </td> <TD class=<TMPL_VAR name="class">> <TMPL_VAR name="content_column_2"> </td> <TR> </TMPL_LOOP> </table>
At this point you can just alternate between values of "loop" or "loop1" in the "bg_class" key in your loop array. If you want to take that one step further, you could pull the class names and background colors themselves into your script, and replace them with template variables in the HTML. This way you could use an array of class name/color pairs which would be accessed by both the style section and the loop data structure. This would allow you to expand to an arbitrary number of background colors to be cycled through. Something like...
<STYLE type="text/css"><!-- <TMPL_LOOP name="style_loop"> TD.<TMPL_VAR name="class"> { background-color: <TMPL_VAR name="color"> +; } --></style>
...for the style section. And...
my @styles = ( { class => "bg_red", color => "#FF0000" }, { class => "bg_green", color => "#00FF00" }, { class => "bg_blue", color => "#0000FF" } );
...for the styles array. Then the main loop would use $styles[$n]->{class} to fill it's data structure, with $n cycling through each element of @styles.

Whoa... okay, so I got a little carried away here. This is probably more than you need, but that's where I'd go with it.

-Bird


In reply to Re: Loop Context Style with HTML::Template by Bird
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.