If you're using HTML::Template and need to cope with the unclean half of ISO-8859-1, the standard procedure is to forego "ESCAPE=HTML" and encode the parameter values yourself, probably using HTML::Entities. But retrofitting a big application to do this can really suck. (Our app has over a hundred templates.)

So rather than going down a road that sucked, I modified HTML::Template 2.7 to support an "encode_entities" option. When true, it runs strings through HTML::Entities::encode_entities rather than HTML::Template's limited built-in encoder. This let us get most of the way to ISO-8859-1 support with a one-line change to our webapp:

my $template = HTML::Template->new( filename => $template, cache => 1, global_vars => 1, + encode_entities => 1, );

The patch (with supporting unit tests) is here.

I've proposed the patch on the html-template-users mailing list. If you're on the list and think it's a good idea, please add your support. Or if you think the idea sucks, say so. But if you think we should switch to TT, come see us 3 years ago. :)

Replies are listed 'Best First'.
Re: ISO-8859-1 support for HTML::Template
by BUU (Prior) on Oct 18, 2004 at 22:19 UTC
    At the risk of posting a useless, uninformative and space wasting node, let me just say:

    Best. Patch. Ever.
Re: ISO-8859-1 support for HTML::Template
by darrellb (Acolyte) on Nov 05, 2004 at 04:15 UTC
    I fixed a bug where the encode_entities option wasn't getting passed in to loops' sub-templates. An updated patch available here. The regression suite was updated, of course. :)
      It's doubly embarrasing when the guy finding the bug sits next to you at work, and that he uses the excuse of finding the bug to finally get a Perlmonks account. Good catch nonetheless. Props also to blakem for co-discovery.