Gossamer Forum
Home : Products : Gossamer Links : Discussions :

UTF-8 and functions in template

Quote Reply
UTF-8 and functions in template
Hi,

I created a custum function to escape HTML-entities. In templates it looks like this:

Code:
<%MYLIB::HTML::entities(' Öckerö')%> - Öckerö

The output was:

Code:
&Ouml;cker&ouml; - Öckerö

Now I changed to UTF-8 and everything works fine, but strings I passed to the function. Now the output is:

Code:
&Atilde;&#150;cker&Atilde;&para; - Öckerö

In the compiled template it is

Code:
$return .= $self->_call_func('MYLIB::HTML::entities', 1, 0, q{Öckerö});

When I use the function in a cgi and pass the result to the template as a variable it is displayed correctly.

Any Ideas? TIA
Quote Reply
Re: [neves] UTF-8 and functions in template In reply to
Oops, forgot to restart apache mod_perl ... embarrassing...
Quote Reply
Re: [neves] UTF-8 and functions in template In reply to
Ok, it was not quite as embarrassing as I thought. (Except that I forgot to restart again;-)) It doesn't work without modification. I changed some lines in GT/Template.pm in sub _call_func. The regexp is from AWstats Plugin decodeutfkeys.

Code:

if ($ok) {
# [MOD START]
require Encode;
# [MOD END]
local $PARSER = $self;
if ($self->{opt}->{heap}) {
push @args, $self->{opt}->{heap}
}
# [MOD START]
@args = map {
if ( $_ =~ m/^(?:[\x00-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf])*$/ ) {
$_ = Encode::decode( "utf-8", $_ );
}
} @args;
# [MOD END]

if ($package and ref($self->{opt}->{func_code}) eq 'CODE') {
$ret = $self->{opt}->{func_code}->($torun, @args);
}