Re: unicode data in ascii template

Bill Moseley <[email protected]> Wed, 8 Jan 2014 09:30:31 -0800
Newsgroups gmane.comp.lang.perl.modules.template-toolkit
Message-ID <CAKhN_m4R0qQO5Km-1Qw9YNKFrso_4KFdpTivejN9k39xGVyhQw@mail.gmail.com>
On Wed, Jan 8, 2014 at 9:22 AM, Dave Howorth <dhoworth-fDajt2Yx3S8pY9vWkoisglpr/1R2p/[email protected]>wrote:

> I have some templates that generate web pages. The templates themselves
> only contain ASCII*.


ASCII is a subset of UTF-8, so I'd use:

  ENCODING => 'UTF-8'.

Then Template::Provider will decode the templates when loading.



> They include some data that is extracted from a
> database and some of the data values are now Unicode UTF-8 (they contain
> non-break space and some quote marks). But the resultant HTML file that
> is generated contains the Windows-1252 code for these characters (i.e.
> single byte values rather than double).
>

Then, as you mentioned in your DBIx::Class post, you need to tell the DBD
driver that your database is in UTF-8.  Then the DBD driver will decode
when reading.

Then you have "characters" inside of Perl.




> What is the best way to persuade TT to generate a Unicode file?
>


I would do something like this:

$tt->process( $template, \%vars, \$output );
$bytes = Encode::encode_utf8( $output );

Or have $output be a filehandle with a utf-8 output layer.



>
> * Actually, there is one sub-template that is PROCESSED that contains a
> Unicode copyright symbol and that is put in the output file unchanged.
> Just to confuse me further.
>

Just make sure you use the utf-8 character for that in your template.

_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates