Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi monks,

I've been using HTML::Template for quite a while now. It has helped greatly in moving a lot of html (and sometimes logic, as when using tmpl_if) out of my code. The result is a more readable code as well as separation of code and html.

When the layout is simple, such as pulling rows of data from a db and displaying them on an html page, it's trivial to achieve a clean separation of code and html.

However, when the page's layout involves quite a bit of logic, I find it sometimes difficult to filter out the html from the code. What I tend to do in such cases is to build up an html string, and then feed that string, together with other tmpl outputs, to the template file.

Do you have that sort of problems? Or are you able to always cleanly compartmentize code and html? I would love to hear from you :)

Thanks in anticipation.

Update: Many thanks to all for sharing :)

It appears the majority find it always possible to separate the program code from the html. There's however some support for the inclusion of html in the code in cases where their separation proves difficult or impossible (in the eyes of the beholder).

Update2: Reading some of the comments, it seems that it's quite common to move the logic from the Perl code to the template (nodes 367304, 367252). amw1 says it's display logic vs processing logic. So it appears to me that some mixing of code and html is inavoidable. It's where that mixing takes place. If part of the logic is moved to the template, then you inevitably have a more complicated template. If the (display) logic resides in the Perl code, then you inevitably have a more complicated Perl code. So perhaps it's a matter of which type of complication you are more comfortable with?


In reply to Code and html separation - always or mostly doable? by kiat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found