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

comment on

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

Your example does not really make a good case for templating. Simple variable substitution is not hard to do without templates. You run into trouble however once you try to dynamically generate tables, lists or such of unpredetermined size.

In that case I find that inlining HTML actively promotes bad programming habits.

I've seen far too often code where little bits of the output are produced by prints strewn throughout various loops and subroutiness here and there and everywhere. Needless to say one change to the layout that requires tags to be changed in concert between several such parts may require hours of scrambling around.

But just a simple change of look isn't even the biggest problem. The real problem with such a style is that you cannot change the alignment of your output without jumping through major hoops. That is, if you had a 2-column vertical output, and you want to change it to a 2-row horizontal output f.ex, you have to change the entire code's logic around to accomodate the new style. UGH. Don't go there.

With templates on the other hand, what your code does is collect all the data into a well-defined data structure, and then hands it all over to the templating mechanism. Even if there are major changes to be made to the way the output is produced, your code's logic never needs touching.

That's why you should use templates. I find that I now use templates for even the simplest of CGIs if the markup I'm going to produce isn't completely static.

____________
Makeshifts last the longest.

In reply to Re: OUTPUT: inline or template_based? by Aristotle
in thread OUTPUT: inline or template_based? by CodeHound

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 wandering the Monastery: (2)
As of 2024-04-25 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found