Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Code and html separation - always or mostly doable?

by saberworks (Curate)
on Jun 17, 2004 at 05:53 UTC ( [id://367540]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Code and html separation - always or mostly doable?
in thread Code and html separation - always or mostly doable?

Both of the above are fine for two colors, but in my code, you can easily add an arbitrary number of colors and it will still work. I think template systems should provide functionality to handle very common cases such as this. Maybe something like (haven't used html::template in forever so I don't remember the syntax for loops, but I'll guess):
<TMPL_LOOP NAME=rows ALTERNATE=FFFFFF,F0F0F0,CCCCCC> <td bgcolor=rows.alternate> .... </td> </TMPL_LOOP>
I guess I could add it ;)

Replies are listed 'Best First'.
Re^4: Code and html separation - always or mostly doable?
by Michalis (Pilgrim) on Jun 17, 2004 at 09:28 UTC
    I thought I'ld let it as an exercise, but...
    If I use bgcolor as integer, not boolean, I can easily do that:
    <td class="color[:bgcolor:]">....</td>

    So I can not only define classes color1,color2 etc, but if in the future we decide we want a 57th special case we haven't thought of before, we don't need to change any code, we just create a class57 and "feed" the bgcolor with the number 57.
    As I said before, there is always a matter of good analysis in order to trully and forever seperate perl code (business logic) from presentation (I consider the loops and if/then/else cases in the final HTML pages to be presentation-specific and not business specific)
    --
    Michalis
      It's an interesting approach, and I like it better than mine, however, I still feel like it's forcing me to "mess with" display logic in the template. I have to start setting bgcolor hash entries which are nothing more than display logic in my data hash. Imagine if I wanted every third row italicized, bolded, or underlined. I'd have to do the same thing (pass it a class in my perl code). Thanks for your help and interesting solutions, I just wish there was a better way. A way in which I can pass the results say directly from fetchall_arrayref to the template and have the template worry about setting the colors.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-19 11:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found