[Templates] keys.sort.grep.join

Anthony Gardner cyclewood_ltd at yahoo.co.uk
Wed Nov 21 13:03:40 GMT 2007


Thanks for the tips and I'm well aware what templates are for ;) This all to do with presentation.

Sergey Martynoff <sergey at martynoff.info> wrote:      
    
   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






Disclaimer: Technically, I'm always wrong!!
       
---------------------------------
 For ideas on reducing your carbon footprint visit Yahoo! For Good this month.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.template-toolkit.org/pipermail/templates/attachments/20071121/29fdc33c/attachment.htm 


More information about the templates mailing list