in reply to HTML::Template - what's the rule of thumb?

Kiat,

We use HTML::Template alot at my work, and i try to follow this general process:

  1. Prior to touching any code at all, I do my best to work with the information-architect and/or graphic-designer/interface-designer (or equivalent person on your team) to try and group "like" pages together. This not only helps me in my coding (and code re-use) but it tends to produce a much smoother end-user experience as well. This is akin to planning out your modules and their interfaces/APIs in software engineering. ( a quick note here: i find sometimes that designers etc. can be resistent to this, its an exercise in diplomacy, but any desinger worth his salt will see if your idea is good, and of course that means you must be just as flexible)

  2. After I feel I have "normalized" as much of the site as i can (sometimes as a programmer you just have to follow the whims of the designers and account folk no matter how silly it may seem to you). Then i begin to plan out my templates. At this point, like pages can be one template (with any nessecary TMPL_IF or TMPL_INCLUDE statements), and unlike pages in seperate templates. Of course this seems straightforward, but without the first step its not so easy.

  3. After I have the templates built, the easiest thing to do is look for repeating sections, and then chunk them out and TMPL_INCLUDE them.

  4. From there, we connect them to the Perl logic and tweak as nessecary.

We use mod_perl, so our templates are cached in the server's process memory. But even with pre-parsed & cached templates, I make an effort to never let my templates get to complex. Complex templates not only have a higher initial parse overhead (longer startup time for mod_perl server/process and slow pages for vanilla CGI), but they tend to be more complex (read: slow) to execute as well. And most importantly, a highly complex template will increase the coupling between your back-end Perl logic and your front end HTML::Template logic which defeats the whole idea of seperation and you are back where you started.

Oh yeah, and i find that the ability of a non-programmer to handle HTML::Templates decreases in relation to the templates complexity. If you are not only trying to seperate display from logic, but trying to seperate tasks across individuals, your better off keeping it simple.

In the end, there is no direct relationship between our perl and our tmpl files, but this has more to do with our particular use of mod_perl (we use handlers not Apache::Registry, and have a whole OO dispatch table architecture set up going on)

Anyway, hope this helps.

-stvn
  • Comment on Re: HTML::Template - what's the rule of thumb?