in reply to Overriding Template Toolkit Internals

There was a recent thread on the Template Toolkit mailing list ([Templates] Filter for HTML entitification?) that may be helpful. I believe that one of the posters posted a patch to Template::Filters which added an "html_all" filter that made use of HTML::Entities. Your approach of creating a separate subclass is probably a better idea, but if the poster's code is to your liking, maybe it could be of some use.

-jehuni

  • Comment on Re: Overriding Template Toolkit Internals

Replies are listed 'Best First'.
Re: Re: Overriding Template Toolkit Internals
by Ovid (Cardinal) on Apr 10, 2002 at 16:46 UTC

    Actually, a reponse to one of my messages to that list lead to the following code:

    package Onsite::Template::Context; use strict; use base qw/ Template::Context /; sub include { my $self = shift; my $template = $_[0]; join "\n", "<!-- START: $template -->", $self->SUPER::include(@_), "<!-- END: $template -->"; } 1;

    Then, in the code that actually uses Template Toolkit:

    use Template; use Template::Config; $Template::Config::CONTEXT = 'Onsite::Template::Context';

    That solved the problem nicely without my rude hack. Basically, the Config module has globals that control all of the modules that it uses. When a Template object is instantiated, &Template::Config::load is called which then will require all modules, allowing them to be overridden at run time. It's a neat solution.

    The only thing about it that bugs me is that I kept reading and reading through the online Template Toolkit documentation and didn't see that anywhere. I'm sure it's there, I just can't find it.

    Cheers,
    Ovid

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