Perrin Harkins wrote:
On Tue, 2006-07-18 at 18:02 +0100, Gavin Henry wrote:
  
What's the proper way ;-)
    

Picking a random one before running the template and passing it in.
(You did ask...)

However, if you just make a sub that does what you want with the list
ref, you can pass a reference to it to TT in the stash and run it:

[ % my_rand_func(tips) %]

- Perrin
  
Hear, Hear for picking it in code rather than the template. :)

But, the needy might also look at the ListUtil Plugin. It has a random list item function.
   http://search.cpan.org/~markf/Template-Plugin-ListUtil-0.02/lib/Template/Plugin/ListUtil.pm

Or make your own Stash OP for it:

 use Template::Stash;
 $Template::Stash::LIST_OPS->{ random } = sub { return $_[0][rand @{$_[0]}] ;};

--mark mills

Reply via email to