X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FTemplate%2FPlugin%2FHTMLFixes.pm;h=ce21b5cd967839e832544762154b02fa03c1c2fd;hb=4270e94242a347cfd105f876d52d1e38b5ca6a19;hp=32d3c56835cd71ed856226355f6aeb75fcc5e97e;hpb=18166576c2ebbeb777700de5f290ac3af23a00fd;p=kivitendo-erp.git diff --git a/SL/Template/Plugin/HTMLFixes.pm b/SL/Template/Plugin/HTMLFixes.pm index 32d3c5683..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; @@ -12,7 +13,7 @@ use Encode; # Replacement for Template::Plugin::HTML::url. -# Strings in Lx-Office are stored in Perl's internal encoding but have +# Strings in kivitendo are stored in Perl's internal encoding but have # to be output as UTF-8. A normal regex replace doesn't do that # creating invalid UTF-8 characters upon URL-unescaping. @@ -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;