dsheroh has asked for the wisdom of the Perl Monks concerning the following question:
I am in the habit of using HTML::Template to generate formulaic output text (HTML or otherwise), but I now find I am accumulating large numbers of templates which are all of the form
This causes much duplication, which bit me today as I needed to make a layout change on a site with about 20 such templates and this change required the addition of a second 'wrapper' div surrounding the existing 'content' div. It was not an incredibly time-consuming task, but definitely tedious.<html> <head> # various information </head><body> <tmpl_include header.tpl> <tmpl_include sidebar.tpl> <div id=content> # actual content </div> <tmpl_include footer.tpl> </body> </html>
This got me thinking that it would be better if I could have a single template establishing that full structure and then <tmpl_include <tmpl_var pagename>.tpl> the actual content based on which page was being loaded at the time. Unfortunately, my various attempts to identify a syntax which allowed this proved futile.
Is there an established way to accomplish this other than by having the content template include two independent templates for the leading and the trailing portions? (I prefer to keep open tag/close tag pairs within the same file so it's easier to verify that they're matched. It's also the only way to have any hope of doing useful validation of the templates themselves.)
While composing this message, it occurred to me that I could read in the meta-template file and use a regex to insert the name of the proper page content template before passing it to HTML::Template for final processing, but I would like to think that there's a better, cleaner way to do it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Variable include names in HTML::Template
by friedo (Prior) on Feb 29, 2008 at 20:34 UTC | |
|
Re: Variable include names in HTML::Template
by Tanktalus (Canon) on Feb 29, 2008 at 23:28 UTC | |
|
Re: Variable include names in HTML::Template
by wfsp (Abbot) on Mar 01, 2008 at 08:34 UTC | |
by dsheroh (Monsignor) on Mar 03, 2008 at 17:38 UTC | |
|
Re: Variable include names in HTML::Template
by reneeb (Chaplain) on Mar 01, 2008 at 12:26 UTC |