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

<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 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.


In reply to Variable include names in HTML::Template by dsheroh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.