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 ();


Copyright © Ben Bullock 2009-2010. All rights reserved. For comments, questions, and corrections, please email Ben Bullock/ Privacy/ Disclaimer