X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/kivitendo-erp.git/blobdiff_plain/c497b0352f95a55d204101b70ac771b2dc21ddee..2ff1c023218df79f45ab9343dc467e123f5eaa82:/SL/Template/Plugin/HTMLFixes.pm diff --git a/SL/Template/Plugin/HTMLFixes.pm b/SL/Template/Plugin/HTMLFixes.pm index 5c6207829..ce21b5cd9 100644 --- a/SL/Template/Plugin/HTMLFixes.pm +++ b/SL/Template/Plugin/HTMLFixes.pm @@ -1,6 +1,7 @@ package SL::Template::Plugin::HTMLFixes; use Template::Plugin::HTML; +use Template::Stash; 1; @@ -21,9 +22,25 @@ no warnings 'redefine'; sub url { my ($self, $text) = @_; return undef unless defined $text; - $text = Encode::encode('utf-8-strict', $text) if $::locale && $::locale->is_utf8; + $text = Encode::encode('utf-8-strict', $text); $text =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg; return $text; } 1; + +package Template::Stash; + +# A method for forcing list context. If a method uses 'wantarray' then +# calling that method from Template will do strange stuff like chosing +# scalar context. The most obvious offender are RDBO relationships. + +# Example of how NOT to test whether or not a customer has contacts: +# [% IF customer.contacts.size %] ... +# Instead force list context and then test the size: +# [% IF customer.contacts.as_list.size %] ... +$Template::Stash::LIST_OPS->{ as_list } = sub { + return ref( $_[0] ) eq 'ARRAY' ? shift : [shift]; +}; + +1;