[Templates] sending perl hash to template
Mark Fowler
mark@twoshortplanks.com
Sun, 29 Sep 2002 21:09:59 +0100 (BST)
On Sun, 29 Sep 2002, allan wrote:
> i have a complete hash in my main perl prgoram which i want to use in
> a template.
> my $vars = {
> person => %person,
> # or maybe \%person,
> };
You want to use a ref here (the '\%person') one. See perlreftut and
perlref[1] for more information on refs.
You can access the contents of the hash from within the template toolkit
with the keys and values virtual methods like so:
[% FOREACH key = product.keys %]
[% key %] is [% product.$key %]
[% END %]
This is documented in the vmethods page[2]
Mark.
[1] http://www.perldoc.com/perl5.8.0/pod/perlreftut.html
http://www.perldoc.com/perl5.8.0/pod/perlref.html
[2] http://www.tt2.org/docs/leon/Manual/VMethods.html#Hash_Virtual_Methods
--
s'' Mark Fowler London.pm Bath.pm
http://www.twoshortplanks.com/ mark@twoshortplanks.com
';use Term'Cap;$t=Tgetent Term'Cap{};print$t->Tputs(cl);for$w(split/ +/
){for(0..30){$|=print$t->Tgoto(cm,$_,$y)." $w";select$k,$k,$k,.03}$y+=2}