Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I am putting together some fairly complicated HTML templates with Template Toolkit, but the many-to-many database relationships do not map well to one-to-many directory structures. As a result, if our designer needs to work on one of the templates, he or she could be hard-pressed to find it. The cleanest solution that occurs to me is to allow the designers to "view source", and see each template delimited by start and end HTML comments that identify the template path:

<!-- START: [% %] --> <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor +="222222"> <tr> <td width="10"><img src="/images/1xshim.gif" width="10" height="1" +></td> <td valign="middle" class="textSubheader" width="100%">Some text</ +td> </tr> </table> <!-- END: [% %] -->

The problem, though, is that I have to hardcode those comments into each template ( is a built-in that lists the path and template). I could write a utility script that goes through and automatically inserts those into templates, if they are not found, but it would be cleaner to simply have Template Toolkit just insert that into the HTML for me. Designers might accidentally remove those comments, or forget to add them to new templates, etc.

My first thought was to use pre and post process configuration options.

my $template = Template->new({ PRE_PROCESS => 'start_tag.tmpl', POST_PROCESS => 'end_tag.tmpl', };

This did not work because I have templates that I INCLUDE into the main template. A careful reading of the docs makes it clear that this is not a feasible solution.

These values may be set to contain the name(s) of template files (relative to INCLUDE_PATH) which should be processed immediately before and/or after each template. These do not get added to templates processed into a document via directives such as INCLUDE, PROCESS, WRAPPER etc.

I've been reading through the docs and can't seem to find anything that seems suitable. My only other thought was to find the appropriate module to subclass and override the INCLUDE directive, but I'd prefer to write the aforementioned utility script than do this. Can anyone present a clean solution to this problem?


Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

In reply to Dynamically altering static TT templates by Ovid

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2021-10-23 02:56 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (86 votes). Check out past polls.