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

i want to know if it is in general possible to process lists ofarray_refs with Template-Toolkit.
i have a sub, returning
return( $sth->fetchall_arrayref);
this should now be processed via Template-Toolkit. but how can this be done? i have a sub
my $t=Fs2::DBrequest::search_pl_entries(1,1,"a");
i tried
## first try ########################################## if ($c{a} eq "c_searchtest") { $vars = { search => $f }; } ########################################## ## second try my @f = @$t; if ($c{a} eq "c_searchtest") { $vars = { search => $t }; } ## and in the template [% FOREACH foo = f %] <pre> START THE OUTPUT [% foo.0 %] [% foo.1 %] </pre> [% END %] ##


but none of the 2 are working. and besides, Template-Toolkit does not output errors, so i don't know what's the story... is it possible to process arrays of array, hashes of arrays, lists of array_refs with Template?

any suggestions or examples out there?

thanks
parasew

update (broquaint): tidied up formatting

Replies are listed 'Best First'.
Re: process lists of array_refs with Template-Toolkit
by jeffa (Bishop) on Oct 20, 2003 at 13:06 UTC

    UPDATE: I just got an email from the Template-Toolkit mailing list - please announce the other forums where you have asked your question in the future. It's just good Netiquette.

    Another example:
    use strict; use warnings; use Template; my $tt2 = Template->new; $tt2->process(\*DATA, { AoA => [ [0,1],[2,3],[4,5] ], AoH => [ {a=>'b'},{c=>'d'} ], }); __DATA__ AoA: [% FOREACH outer_a = AoA -%] [% FOREACH inner_a = outer_a -%] [% inner_a %] [% END -%] [% END -%] AoH: [% FOREACH outer_h = AoH -%] [% FOREACH key = outer_h.keys.sort -%] [% key %] => [% outer_h.$key %] [% END -%] [% END -%]

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: process lists of array_refs with Template-Toolkit
by antirice (Priest) on Oct 20, 2003 at 11:13 UTC

    Example:

    #!/usr/bin/perl -wl use strict; use Template; my $template = <<'END_OF_TEMP'; [% FOREACH foo = f %] <pre> START THE OUTPUT [% foo.0 %] [% foo.1 %] </pre> [% END %] END_OF_TEMP my $tt2 = Template->new(); my $vars = { f => [ [ qw(0 1) ] ] # array of arrays }; $tt2->process(\$template,$vars);

    Hope this helps.

    antirice    
    The first rule of Perl club is - use Perl
    The
    ith rule of Perl club is - follow rule i - 1 for i > 1