Hello,
how can I sort hash reference by values, I found some solution:
http://mail.template-toolkit.org/pipermail/templates/2005-June/007501.html
But I don't know where can I add virtual method.
3) Similar to 2. Add a virtual method to your hashes. Just add this above your
process call. (Note: You might need to add: 'use Template::Stash;') :
$Template::Stash::HASH_OPS->{ sort_keys_by } = sub {
my ($hash, $sort_field) = @_;
return sort {
$hash->{$a}->{$sort_field}<=> $hash->{$b}->{$sort_field}
} keys %$hash
};
then you can do:
[% FOREACH r = ref.sort_keys_by('number') %]
<a href="/program?id=[% r %]">[% ref.$r.title _ " " _ ref.$r.number %]</a>
[% END %]
I try to add virtual method to View but i get error:
|Couldn't render template "stats.tt: undef error - Can't use string ("1") as a HASH ref
while "strict refs" in use at View/HTML.pm line 15.|
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/