How to use UtF-8 characters in Petal Templates

Peter Mayr <[email protected]> Thu, 27 Sep 2012 14:25:11 +0200
Newsgroups gmane.comp.lang.perl.modules.petal
Message-ID <[email protected]>
Hi!

we really like the Petal Templating-Engine for our webservices, however=20
I ran into a small problem:
How can I use UTF-8 characters in Templates?
It seems to me that they are all encoded to ISO-Latin-1.

Here is a small test case:

testcase.pl
-----
#!/usr/bin/env perl

use strict;
use warnings;
use utf8;

use Petal;

print "Petal with options: output =3D> XHTML\n";
my $Template =3D new Petal(
         file           =3D> "test.xml",
         output         =3D> 'XHTML',

     );

print $Template->process();

print "\n\nPetal with options: output =3D> XML\n";

$Template =3D new Petal(
         file           =3D> "test.xml",
         output         =3D> 'XML',

     );

print $Template->process()."\n";

print "Petal with options: output =3D> XHTML, decode_charset =3D> utf-8\n=
";
my $Template =3D new Petal(
         file           =3D> "test.xml",
         output         =3D> 'XHTML',
         decode_charset =3D> 'utf-8',
     );

print $Template->process();

print "\n\nPetal with options: output =3D> XML, decode_charset =3D> utf-8=
\n";

$Template =3D new Petal(
         file           =3D> "test.xml",
         output         =3D> 'XML',
         decode_charset =3D> 'utf-8',
     );

print $Template->process()."\n";
-----

test.xml (file is UTF-8 acc. to emacs)
-----
?xml version=3D"1.0" encoding=3D"UTF-8" standalone=3D"yes"?>
<ul  xmlns:tal=3D"http://purl.org/petal/1.0/">
  <li>UTF-8 Umlaut: =E4</li>
  <li>HTML Entity:  &uuml;</li>
  <li>Entity with Hex-Code:&#xFC;</li>
</ul>
-----

Does anyone of you have some tips or pointers?

Thanks in advance!

  All the best,

  Peter

--=20
Peter Mayr, MA LIS
hbz, Gruppe Portale
- DigiBib, Online-Fernleihe -
Postfach 270451, 50510 K=F6ln, Deutschland
Telefon +49-221-40075-198, Fax +49-221-40075-190
[email protected]
http://www.hbz-nrw.de