Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1bdfacee

Von Moritz Bunkus vor etwa 11 Jahren hinzugefügt

  • ID 1bdfacee11393f18563ccd8143a9408f07449ede
  • Vorgänger 85f6594f
  • Nachfolger 5b192e71

Template: as_list-Methode zum Forçieren vom Listenkontext

Unterschiede anzeigen:

SL/Template/Plugin/HTMLFixes.pm
1 1
package SL::Template::Plugin::HTMLFixes;
2 2

  
3 3
use Template::Plugin::HTML;
4
use Template::Stash;
4 5

  
5 6
1;
6 7

  
......
27 28
}
28 29

  
29 30
1;
31

  
32
package Template::Stash;
33

  
34
# A method for forcing list context. If a method uses 'wantarray' then
35
# calling that method from Template will do strange stuff like chosing
36
# scalar context. The most obvious offender are RDBO relationships.
37

  
38
# Example of how NOT to test whether or not a customer has contacts:
39
#   [% IF customer.contacts.size %] ...
40
# Instead force list context and then test the size:
41
#   [% IF customer.contacts.as_list.size %] ...
42
$Template::Stash::LIST_OPS->{ as_list } = sub {
43
  return ref( $_[0] ) eq 'ARRAY' ? shift : [shift];
44
};
45

  
46
1;

Auch abrufbar als: Unified diff