in reply to Template and Unicode (was: Re: Another Unicode/emoji question)
in thread Another Unicode/emoji question

It was several years in the past, but I have used Template with unicode a lot. You can have UTF-8 encoded templates and UTF-8 strings in variables - you just need to declare them consistently.

The very first configuration parameter documented in Template::Manual::Config is ENCODING. I'll quote it here because it is so short:

ENCODING

The ENCODING option specifies the template files' character encoding:

my $template = Template->new({ ENCODING => 'utf8', });

A template which starts with a Unicode byte order mark (BOM) will have its encoding detected automatically.

So, the following program works as I'd expect:

use Template; use open ":std", ":encoding(UTF-8)"; my $dogface = "\N{DOG FACE}"; my $template = <<"ENDOFTEMPLATE"; Dog face from template: $dogface Dog face from variable: [% dogface %] ENDOFTEMPLATE my $tt = Template->new(ENCODING => 'UTF-8'); $tt->process(\$template,{dogface => $dogface});

The automatic BOM detection is a handy band-aid if you have a mixture of Latin1 and UTF-8 encoded templates and don't want to re-code them.