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. :)


In reply to ISO-8859-1 support for HTML::Template by dws

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.