<div dir="ltr"><div dir="ltr"><div>In the meantime I wrote an example using Dancer as well, though I used a different dataset:</div><div><br></div><div><a href="https://code-maven.com/slides/perl/showing-hash-of-hashes">https://code-maven.com/slides/perl/showing-hash-of-hashes</a></div><div><br></div><div>regards<br></div></div><div>   Gabor</div><div><br></div><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Aug 23, 2020 at 5:57 PM Gabor Szabo <<a href="mailto:gabor@szabgab.com">gabor@szabgab.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Have you checked the content when you "view source" in the browser?</div><div>I had cases when my code did not show up because I had some HTML issues.</div><div>I wasted so much time till I figured out the content is there just hidden.</div><div><br></div><div>My example is stand-alone using Template::Toolkit,</div><div>when using Dancer you don't need that, you only need to enable it in the config file</div><div>and you pass your data to the "template" function.</div><div><br></div><div>The TT part is almost identical though I think in Dancer we use <% for tags and not</div><div>the default [% as in my example.<br></div><div><br></div><div>Gabor<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Aug 23, 2020 at 5:46 PM Richard Reina <<a href="mailto:gatorreina@gmail.com" target="_blank">gatorreina@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Gabor,<br>
<br>
Thank you very much for your help. I appreciate your answer and all<br>
the wonderful tutorials at perlmaven, but so far I am unable to get<br>
this answer to work for me. My my hash %season seems to look the same<br>
as your %payload but when I try your solution only the name of the<br>
player is displayed. I do not use 'use Template'; in my backend code<br>
and am not really sure what the exact role of <a href="http://create.pl" rel="noreferrer" target="_blank">create.pl</a>, is it for<br>
teaching purposes or is there a step within it that I must apply to<br>
get my %season to look like your %payload before I return it to my<br>
Dancer app? I will continue to experiment with your solution and try<br>
to find a place where I can post exactly what I am getting as a<br>
result.<br>
<br>
Thanks again,<br>
<br>
Richard<br>
<br>
2020-08-23 7:18 GMT-05:00, Gabor Szabo <<a href="mailto:gabor@szabgab.com" target="_blank">gabor@szabgab.com</a>>:<br>
> I am not sure if this is what you meant, but using your data I wrote two<br>
> examples here: <a href="https://perlmaven.com/template-toolkit-hash-of-hash" rel="noreferrer" target="_blank">https://perlmaven.com/template-toolkit-hash-of-hash</a><br>
><br>
> Gabor<br>
><br>
> On Sun, Aug 23, 2020 at 12:33 AM Richard Reina <<a href="mailto:gatorreina@gmail.com" target="_blank">gatorreina@gmail.com</a>><br>
> wrote:<br>
><br>
>> I have the following perl multidimensional hash that is passed from<br>
>> Dancer to Template Toolkit as a hash reference. I am having trouble<br>
>> figuring out how to display it in Template Toolkit.<br>
>><br>
>> $VAR1 = {<br>
>>           'TylerMontgomery(2022)' => {<br>
>>                                    'so' => 1,<br>
>>                                    'bb' => 1,<br>
>>                                    'rbis' => 0,<br>
>>                                    'atbats' => 7,<br>
>>                                    'runs' => 2,<br>
>>                                    'hits' => 2<br>
>>                                  },<br>
>>           'ChaseLangan(2022)' => {<br>
>>                                      'runs' => 4,<br>
>>                                      'hits' => 4,<br>
>>                                      'atbats' => 5,<br>
>>                                      'bb' => 0,<br>
>>                                      'rbis' => 2,<br>
>>                                      'so' => 1<br>
>>                                    },<br>
>>           'BryceJones(2021)' => {<br>
>>                             'hits' => 2,<br>
>>                             'runs' => 2,<br>
>>                             'atbats' => 4,<br>
>>                             'bb' => 1,<br>
>>                             'rbis' => 4,<br>
>>                             'so' => 1<br>
>>                           },<br>
>> };<br>
>><br>
>> This is how I iterate it in perl.<br>
>><br>
>> foreach my $name (sort keys %season) {<br>
>>         printf "%-27.27s", "$name: ";<br>
>>         foreach my $stat (sort keys %{ $season{$name} }) {<br>
>>             printf "%-12.12s", "$stat: $season{$name}{$stat} ";<br>
>>          ## cal. avg<br>
>>  $season{$name}{AVG} = $season{$name}{hits} / $season{$name}{atbats};<br>
>>         }<br>
>><br>
>><br>
>>     printf "%4s %.3f\n", "avg:", $season{$name}{AVG};<br>
>> }<br>
>><br>
>> I then pass it back to my dancer app as a ref. with return \%season;<br>
>> and then to template toolkit with:<br>
>><br>
>>   template '<a href="http://softball.tt" rel="noreferrer" target="_blank">softball.tt</a>' => {<br>
>><br>
>>         'title' => 'Get Softball Season Stats',<br>
>>         'Season' => $season,<br>
>><br>
>><br>
>>     }, {};<br>
>><br>
>> But I am lost trying to get it to display with template toolkit.<br>
>> Here's what I've tried so far.<br>
>><br>
>> <table style="width:100%; line-height:40px;"><br>
>>         <% FOREACH Season = Season %><br>
>>         <tr><br>
>>           <td width="5">Season.key <% Season.key %></td><br>
>>           <td width="5">Season.val <% Season.value %></td><br>
>>           <td width="5">Season.val.atbats <% Season.value.atbats %><br>
>>           <td width="5">Season.val.hits <% Season.value.hits %><br>
>>         </tr><br>
>>         <% END %><br>
>><br>
>> Thanks for any help.<br>
>> _______________________________________________<br>
>> dancer-users mailing list<br>
>> <a href="mailto:dancer-users@lists.preshweb.co.uk" target="_blank">dancer-users@lists.preshweb.co.uk</a><br>
>> <a href="https://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">https://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
>><br>
><br>
</blockquote></div></div>
</blockquote></div></div></div>