I first asked this question on Perlmonks
(http://www.perlmonks.org/index.pl?node_id=156772) and was directed here.
You might find some of the replies there helpful.

----

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
(templates are served from directories). 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: [% component.name %] -->
    <table>
      <tr>
        <td>Some text</td>
      </tr>
    </table>
    <!-- END: [% component.name %] -->

The problem, though, is that I have to hardcode those comments into each
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.  From the docs:

    "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
(Template::Context?) 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?

Note that one of the suggestions was that PRE_INCLUDE and POST_INCLUDE
directives would be nice...

Cheers,
Curtis "Ovid" Poe
--
"Ovid" on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//;
shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A



Reply via email to