Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

ISO-8859-1 support for HTML::Template

by dws (Chancellor)
on Oct 18, 2004 at 21:26 UTC ( #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. :)

Comment on ISO-8859-1 support for HTML::Template
Download Code
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
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? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2014-12-29 02:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls