The normal workflow is:
- Decode all incoming data (with Encode::decode or with an IO layer)
- Work with your data
- Encode all outgoing data (with Encode::encode or an IO layer)
The problem is that HTML::Template doesn't support step one - it always reads templates as binary data. Once you mix that with decoded data, you're lost.
One solution is to use HTML::Template::Compiled, which is a drop-in replacement for HTML::Template, and which has the open_mode option to new - just create your templates with
use HTML::Template::Compiled;
my $t = HTML::Template::Compiled->new(
filename => 'mytemplate.phtml',
open_mode => '<:encoding(UTF-8)',
);
Another "solution" is to encode every string that is passed to HTML::Template, but this will make your code explode (in terms of size, anyway).
Update: a few debugging tips when dealing with charset issues:
- In firefox press Ctrl+I to see the encoding that is actually used to display the page
- Check your error.log (or STDERR) for "wide character in print"-warnings - it means that you forgot an IO-Layer or a encode_utf8 somewhere.
- Use Devel::Peek to inspect your data - watch out for that UTF-8 flag
2nd update: you might have confused "encode" and "decode" - you have to decode input data from the outside (Foreign data -> Perl text strings) and you have to encode data in the other direction (Perl text strings -> Rest of World).
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.