Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Has anyone tried feeding a hash of a hash into the template tool kit? i'm having trouble doing this. heres the perl code it prints out just fine but when i pass it to the template it doesnt do anything perl code
foreach my $i (keys %results){ print "rule_id - $i\n"; foreach my $k (keys %{$results{$i}}){ print "$k -> $results{$i}->{$k}\n"; } print "----------------------------------\n"; } $self->process_template( template => $login_template, data => { resu +lts => \%results});
Template toolkit code
[% FOREACH r = results %] [% r %] <---- this prints out a hash [% END %]

Replies are listed 'Best First'.
Re: hash of a hash into template toolkit?
by DamnDirtyApe (Curate) on Jul 04, 2002 at 00:57 UTC
    [% FOREACH r = results %] [% r %] <---- this prints out a hash [% END %]

    That's because r is a hash reference. If you want to show data in r, you need to say something like

    [% FOREACH r = results %] [% r.foo %] and [% r.bar %] [% END %]

    Read all about it in the Template Toolkit's manual, section on Hash Array References.

    Also, from looking at the code above, you may benefit from reading the Data::Dumper docs. It's typically a much handier way of displaying a data structure than rolling your own.


    _______________
    D a m n D i r t y A p e
    Home Node | Email