[dancer-users] How tod displaye aMulti Dimesional Hash in Template Toolkit
Clive Eisen
clive at hildebrand.co.uk
Sun Aug 23 06:33:47 EDT 2020
You don't show what your tests render
Like in perl Dumper is your friend
http://www.template-toolkit.org/docs/modules/Template/Plugin/Dumper.html <http://www.template-toolkit.org/docs/modules/Template/Plugin/Dumper.html>
—
Clive Eisen
GPG: 3818B5F1
> On 22 Aug 2020, at 22:32, Richard Reina <gatorreina at gmail.com> wrote:
>
> I have the following perl multidimensional hash that is passed from
> Dancer to Template Toolkit as a hash reference. I am having trouble
> figuring out how to display it in Template Toolkit.
>
> $VAR1 = {
> 'TylerMontgomery(2022)' => {
> 'so' => 1,
> 'bb' => 1,
> 'rbis' => 0,
> 'atbats' => 7,
> 'runs' => 2,
> 'hits' => 2
> },
> 'ChaseLangan(2022)' => {
> 'runs' => 4,
> 'hits' => 4,
> 'atbats' => 5,
> 'bb' => 0,
> 'rbis' => 2,
> 'so' => 1
> },
> 'BryceJones(2021)' => {
> 'hits' => 2,
> 'runs' => 2,
> 'atbats' => 4,
> 'bb' => 1,
> 'rbis' => 4,
> 'so' => 1
> },
> };
>
> This is how I iterate it in perl.
>
> foreach my $name (sort keys %season) {
> printf "%-27.27s", "$name: ";
> foreach my $stat (sort keys %{ $season{$name} }) {
> printf "%-12.12s", "$stat: $season{$name}{$stat} ";
> ## cal. avg
> $season{$name}{AVG} = $season{$name}{hits} / $season{$name}{atbats};
> }
>
>
> printf "%4s %.3f\n", "avg:", $season{$name}{AVG};
> }
>
> I then pass it back to my dancer app as a ref. with return \%season;
> and then to template toolkit with:
>
> template 'softball.tt' => {
>
> 'title' => 'Get Softball Season Stats',
> 'Season' => $season,
>
>
> }, {};
>
> But I am lost trying to get it to display with template toolkit.
> Here's what I've tried so far.
>
> <table style="width:100%; line-height:40px;">
> <% FOREACH Season = Season %>
> <tr>
> <td width="5">Season.key <% Season.key %></td>
> <td width="5">Season.val <% Season.value %></td>
> <td width="5">Season.val.atbats <% Season.value.atbats %>
> <td width="5">Season.val.hits <% Season.value.hits %>
> </tr>
> <% END %>
>
> Thanks for any help.
> _______________________________________________
> dancer-users mailing list
> dancer-users at lists.preshweb.co.uk
> https://lists.preshweb.co.uk/mailman/listinfo/dancer-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20200823/4932d2ce/attachment.htm>
More information about the dancer-users
mailing list