Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Handling Encoding in Templates

by Rhandom (Curate)
on Nov 12, 2007 at 19:12 UTC ( #650347=note: print w/ replies, xml ) Need Help??


in reply to Handling Encoding in Templates

Thanks to the patches by Carl Franks, Template::Alloy has included the ENCODING parameter since version 1.008 (which was released several weeks ago).

This means that you can use ENCODING on both TT2 style templates, as well as on HTML::Template templates and Text::Tmpl templates since Template::Alloy supports them all.

The following example shows usage for setting the encoding - though it is only pulling from a code ref in this example, the encoding works properly when a filename is used rather than a string ref.

use strict; use warnings; use Template::Alloy; my $t = Template::Alloy->new(ENCODING => 'UTF-8'); my $in = "[% foo %]|BAR ¥"; my $foo = 'fü'; my $out = ''; $t->process(\$in, {foo => $foo}, \$out) || die $t->error; print "\$out: $out\n"; # Prints # $out: fü|BAR ¥

my @a=qw(random brilliant braindead); print $a[rand(@a)];


Comment on Re: Handling Encoding in Templates
Download Code
Re^2: Handling Encoding in Templates
by moritz (Cardinal) on Nov 12, 2007 at 19:56 UTC
    Great, it works like a charm. Thanks to you and Carl Franks!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://650347]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2014-12-29 05:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (184 votes), past polls