Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Trying to understand template-foo

by xtype (Deacon)
on Sep 13, 2003 at 21:37 UTC ( [id://291293]=note: print w/replies, xml ) Need Help??


in reply to Trying to understand template-foo

"like how you're meant to do stuff like switching the row color on alternate lines."

Admittedly this is a very small point in your questions, however, I already had the file open, so I thought, why not cut and paste this for you... knock off the small ones. :^)

perl:
my $bgcolor = "#d7d7d7"; for(@{$item_ref}) { $bgcolor = ($bgcolor eq "#d7d7d7") ? "#f7f7f7" : "#d7d7d7"; push @{$nodes}, { title => $q->escapeHTML($_->{'title'}), text => $_->{'text'}, inid => $_->{'inid'}, timestamp => localtime( epochtime($_->{'timestamp'}) ), bgcolor => $bgcolor, }; }
template:
<table border="1" cellpadding="2" cellspacing="0"> <!-- snip --> <tmpl_loop nodes> <tr bgcolor="<tmpl_var bgcolor>"> <td align="right"><tmpl_var title></td> <td rowspan="2"><tmpl_if inid><a href=?idisplay&img=<tmpl_var inid +> target=_blank><img src=?getimage&img=<tmpl_var inid>&thumb border=0 +></a><tmpl_else>&nbsp;</tmpl_if></td> </tr><tr bgcolor="<tmpl_var bgcolor>"> <td colspan="3">Last modified <tmpl_var timestamp> by <tmpl_va +r user></td> </tr><tr bgcolor="<tmpl_var bgcolor>"> <td colspan="4"><tmpl_var text></td> </tr> </tmpl_loop> </table>

Possibly there is a cleaner/better way, if so I am sure I will hear about it.

ciao, -xtype

update: Actually, you have caused me to re-evaluate that. You should keep the colours in the template or the style sheet, not in the perl!
So instead do something like this:
<tr bgcolor="<tmpl_if switch_colour>#d7d7d7<tmpl_else>#f7f7f7</tmpl_if +>"> or <tr id="<tmpl_if switch_colour>every<tmpl_else>other</tmpl_if>">

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://291293]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-24 22:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found