· 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.· Introduction
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.
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.· No HTML tags should be in the Perl code
To truly separate logic and design,
- no HTML tags should be in the Perl code, and
- no logic should be in the HTML template
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.· One way
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.
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.· Another way
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 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))).· Conclusion
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.
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: HTML - sharing design and logic
by dfaure (Chaplain) on Jul 01, 2004 at 12:59 UTC | |
Re: HTML - sharing design and logic
by perrin (Chancellor) on Jul 01, 2004 at 15:00 UTC | |
Re: HTML - sharing design and logic
by hardburn (Abbot) on Jul 01, 2004 at 12:57 UTC | |
by cees (Curate) on Jul 01, 2004 at 17:47 UTC | |
by muba (Priest) on Jul 01, 2004 at 20:24 UTC | |
by muba (Priest) on Jul 01, 2004 at 13:00 UTC | |
by hardburn (Abbot) on Jul 01, 2004 at 13:13 UTC | |
by saskaqueer (Friar) on Jul 01, 2004 at 17:35 UTC | |
by hardburn (Abbot) on Jul 01, 2004 at 18:56 UTC | |
by BUU (Prior) on Jul 01, 2004 at 17:57 UTC | |
by hardburn (Abbot) on Jul 01, 2004 at 18:59 UTC | |
| |
by thraxil (Prior) on Jul 02, 2004 at 00:57 UTC | |
Re: HTML - sharing design and logic
by kiat (Vicar) on Jul 01, 2004 at 14:04 UTC | |
Re: HTML - seperating design and logic
by l3nz (Friar) on Jul 03, 2004 at 08:09 UTC | |
Re: HTML - seperating design and logic
by MidLifeXis (Monsignor) on Jul 01, 2004 at 17:41 UTC | |
Re: HTML - seperating design and logic
by submersible_toaster (Chaplain) on Jul 03, 2004 at 11:45 UTC |
Back to
Meditations