Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

ISO-8859-1 support for HTML::Template

by dws (Chancellor)
on Oct 18, 2004 at 21:26 UTC ( [id://400329]=perlmeditation: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://400329]
Approved by kvale
Front-paged by cbraga
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2024-04-24 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found