|Think about Loose Coupling|
Dynamically altering static TT templatesby Ovid (Cardinal)
|on Apr 04, 2002 at 21:11 UTC||Need Help??|
Ovid has asked for the wisdom of the Perl Monks concerning the following question:
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:
The problem, though, is that I have to hardcode those comments into each template (component.name 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.
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.