Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Variable include names in HTML::Templateby dsheroh (Monsignor) |
on Feb 29, 2008 at 18:47 UTC ( [id://671259]=perlquestion: print w/replies, xml ) | Need Help?? |
dsheroh has asked for the wisdom of the Perl Monks concerning the following question:
Brothers,
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. 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.
Back to
Seekers of Perl Wisdom
|
|