I have a web page which answers your question here:

http://www.lemoda.net/perl/template-encoding/index.html

The content is as follows:

Using Perl's Unicode encoding with the template toolkit

In order to use Perl's internal Unicode encoding with the Template
Toolkit, Template, and UTF-8 encoded files, it is necessary both to
specify the encoding when creating the template object, and to specify
a fourth argument to the object's process command, consisting of a
hash reference {binmode => ':utf8'}:

use Template;
# Give the object an argument ENCODING
my $tt = Template->new ({ENCODING => 'utf8'});
# Add a fourth argument to "process":
$tt->process ("input_file_name", $variables, $output_scalar,
          {binmode => ":utf8"})
    or die $tt->error ();

It's the first hit if I search for "template toolkit unicode" in Google.

I believe I got this answer from this mailing list a few years ago,
but don't have an exact recollection.

I hope this helps.


On 9 January 2014 02:22, Dave Howorth <[email protected]> wrote:
> I have some templates that generate web pages. The templates themselves
> only contain ASCII*. 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).
>
> What is the best way to persuade TT to generate a Unicode file?
>
> * 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.
>
> IIUC when strings are joined, Perl should automatically 'upgrade' them
> from ASCII to Unicode if necessary, so it seems TT isn't looking at what
> type of string it has when it comes to write out the file? But I expect
> I've misunderstood something.
>
> _______________________________________________
> templates mailing list
> [email protected]
> http://mail.template-toolkit.org/mailman/listinfo/templates

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

Reply via email to