[Catalyst] pass array to template?

Matt S Trout dbix-class at trout.me.uk
Wed Jun 28 21:47:44 CEST 2006


Sarah Berry wrote:
> How can I pass an array to Template Toolkit, then loop through it? I'm
> trying to pass it through the stash just like anything else, as
> follows:
> 
> in .pm file:
>         my @numtextCaps = ("Zero", "One", "Two", "Three", "Four",
> "Five", "Six", "Seven", "Eight");
>         $c->stash->{numarray} = @numtextCaps;
> 
> in .tt file:
> [% FOREACH word = numarray %]
> <h3>[% word %]</h3>
> [% END %]
> 
> The loop only iterates once, and prints out:
> 9
> at that one iteration.
> My code seems to match the way the foreach loop is done in the
> Template Toolkit documentation, so I must be missing something in the
> way TT interacts with Catalyst?

$c->stash->{numarray} = \@numtextCaps;

As we said on the DBIC list, read perldoc perlreftut and perlref for full info 
about how all this works.

-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the Catalyst mailing list