RE: [phplib] templates: toggling blocks From: Brian Popp (bpopp <email protected>)
Date: 04/16/01

Here's what I do:

while ( $db->next_record() )
{
        $bgcolor = ($colcount++ % 2) ? "#808080" : "#FFFFFF";
        $t->set_var ( "bgcolor", $bgcolor );
}

Each time through the loop colcount gets incremented and then modulas'd by
2. If there's a remainder, the bg is 808080 otherwise ffffff. In the
template you would have <TR BGCOLOR='{bgcolor}'> inside your record block.

I guess you're right.. this doesn't completely isolate your presentation
from code, but it has worked well for me. As the great Bruce Lee used to
say, learn it all.. use what works.

bpopp - bpopp.net

-----Original Message-----
From: Jens Benecke [mailto:jens <email protected>]
Sent: Saturday, April 14, 2001 2:29 PM
To: PHPLIB
Subject: [phplib] templates: toggling blocks

Hi,

on many sites that output a list of some sort, alternating background
colors are used so that you keep track of where you are reading in the
list.

How would I accomplish this with PHPLIBs templates? Is there a cleaner
solution than defining a CSS variable as {CSS} and then set_var'ing this
over the result-loop? (which would mean that I'm not strictly separating
design from code any more, which I dislike)

Or had I better use sqltable for this?

-- 
Jens Benecke                   "Und deshalb sollte man ja auch immer _alle_
                                 Editoren installieren:  XEmacs _und_ Vim."
				                             -- Sven Guckes
http://www.hitchhikers.de/ - Die kostenlose Mitfahrzentrale für ganz Europa

--------------------------------------------------------------------- To unsubscribe, e-mail: phplib-unsubscribe <email protected> For additional commands, e-mail: phplib-help <email protected>