Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
· Prologue
I am aware of the fact that something of the same subject has recently been posted at PerlMonks. I am also aware of the fact that people have written many texts about this subject, both at PerlMonks and many other places. Also am I aware of the fact that this node possibly does not tell you something new.
The main reason for writing this, was that I was thinking about HTML::Template and it's idea and I felt I needed to share my thoughts with others.
So, thank you in advance for reading my thoughts.

· Introduction
Recently, I read the documentation of HTML::Template. I think the idea behind this kind of modules is rather interesting, although sometimes not too consistent.
To truly separate logic and design,
  1. no HTML tags should be in the Perl code, and
  2. no logic should be in the HTML template
· No HTML tags should be in the Perl code
Well, the first thing is not too difficult: while writing your Perl code, just imagine that readers of your page should be able to read it with interpreters of any mark up language. Imagine HTML::Template could be LaTeX::Template, POD::Template, Man::Template or whatever else template as well.

· No logic should be in the HTML template
Of course, a little logic is allowed, for example to create rows that have different colors (the odd numbered rows are white, the even numbered rows are grey) and such things. Just not too many logic.

· Let's have a look at PerlMonks
No, I am not going to critizise PM. I was just thinking how PerlMonks would be written if it would use HTML::Template (does it, actually)? For example, let's have a look at the nodelets column.
PM offers a couple of nodelets, all of which have other contents (XP Nodelet: only text; Personal Nodelet: links which the user can specify, chatterbox: text and a form, voting booth: a form).
Not only are users able to choose which nodelets they want to see, also they're able to choose in which order the nodelets will be shown.

· One way
The very easiest way of implementing this, is to just create a loop in the HTML template, that uses only two variables: nodelet_title and nodelet_contents. The contents, in this case, will contain HTML tags to create the links and forms and such. So this violates the first rule.
This way, if you want to create a new nodelet, you only have to modify the Perl script. The template will automatically accept the new nodelet because it will get the title and the contets just in one of the iterations of the loop.

· Another way
Another way is to create a loop which will get the nodelet titles. Then, for every title you make an if-tag and within the if-tag, the proper variables are retrieved (eventually with the use of loops (within loops (within loops))).
This moves the design issues to the template. Also, it moves much of the logic to the template. Besides, if you want to create a new nodelet, both the Perl code and the template need to support the new nodelet.

· Conclusion
I think it is never trully possible to separate design and logic, unless with a fairly simple interface where everything will be as the coder and/or designer wants it to be. Whenever it gets more complex (more customizable for instance) it will become harder to separate the two.
Update: fixed some typo's and grammar errors. Thanks to injunjoel

In reply to HTML - separating design and logic by muba

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 taking refuge in the Monastery: (5)
As of 2024-03-28 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found