[Templates] keys.sort.grep.join
Sergey Martynoff
sergey at martynoff.info
Wed Nov 21 11:46:26 GMT 2007
Am trying to get some Perl code into a template (to do with presentation ;)
)
How can I do the following in TT without using a FOREACH? Just pointing me
to the right place in the docs would be great. Sadly, TT doesn't have map
(or at least I can't find it in vmethods etc.)
Perl
$result = join( ',', map{ $my_hash->{A_KEY}->{$_} }
grep{ ! /some_string/ }
sort keys %{$my_hash->{A_KEY}}
);
Templates are for data presentation, not for programming! ;)
There's no way to do "map" in pure TT syntax - so you have to choose:
1) Prepare and filter your data in perl code (data source, etc) and then
pass it to template
2) Use FOREACH with NEXT UNLESS key.match('some_string')
3) Write TT plugin for your needs and [% USE %] it in template
4) Embed perl code in TT using [% PERL %] block
--
Sergey Martynoff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.template-toolkit.org/pipermail/templates/attachments/20071121/3e824fba/attachment.htm
More information about the templates
mailing list