Hello all,

I've been trying to write a CGI::Application application using Template
Toolkit for templating.  But I've come across some odd behavior.

My template loads OK, but when the variables contain utf8 characters then
weird things happen to the either characters in the template or the ones in
the variables.

This problem is reproducible on my system.  Template::Toolkit  2.22 Perl
5.10.1

I've written a little script that demonstrates it and have attached the
files to this email.

The output is as follows:

___ Replacing just ASCII ___
In template file: a à â c ç e é è ê ë i ï o ô u û ù
Replaced items  : a c e i o u


___ Replacing with explicit unicode character ___
Wide character in print at /usr/lib/perl5/Template.pm line 163.
In template file: a à â c ç e é è ê ë i ï o ô u û ù
Replaced items  : ☺ a à â c ç e é è ê ë i ï o ô u û ù


___ Replacing with written unicode - we are 'use-ing' utf8 ___
In template file: a à â c ç e é è ê ë i ï o ô u û ù
Replaced items  : a � � c � e � � � � i � o � u � �

You can see that in the first example the unicode characters in the template
are output as they should be.  In the second they are not. In the third it's
the utf8 text in the variables that is coming out all odd.

Has anyone got any ideas what might be going on here?

Attachment: example_french
Description: Binary data

#!/usr/local/bin/perl
use strict;
use utf8;
use open ':encoding(utf8)';

use Template;
my $tt = Template->new( { INCLUDE_PATH => "." } );

print "\n\n";
print "___ Replacing just ASCII ___ \n";
$tt->process('example_french', { replace => "a c e i o u" } );
print "\n";

print "\n\n___ Replacing with explicit unicode character ___ \n";
$tt->process('example_french', { replace => "\x{263a} a à â c ç e é è ê ë i ï o ô u û ù" } );
print "\n";

print "\n\n___ Replacing with written unicode - we are 'use-ing' utf8 ___ \n";
$tt->process('example_french', { replace => "a à â c ç e é è ê ë i ï o ô u û ù" } );
print "\n";
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to