http://qs1969.pair.com?node_id=1178180


in reply to Dancer2 Template Toolkit interpolation

G'day cLive ;-),

By using the data structure you show ($vars in my code below), I'm getting the type of output I assume you're expecting. So, given the code and data you show, I can't reproduce your problem.

By making a change to that data structure ($vars2), I can reproduce the type of output you're describing.

"I have the following data getting sent to the template"

I'd first confirm that with Data::Dumper (or similar). If that gets you nowhere, try hard-coding that hashref to see if you get the same results. You could also try running my test code, as is, and see if you're getting the same output as me.

Here's my test code:

#!/usr/bin/env perl use strict; use warnings; use Template; my $input = <<'EOT'; <p>ed=[% ed %] ad=[% ad %]</p> <table> <tr><th>First</th><th>Last</th></tr> [% FOREACH voter IN voters %] <tr> <td>[% voter.firstname %]</td> <td>[% voter.lastname %]</td> </tr> [% END %] </table> EOT my $vars = { ed => 'ED', ad => 'AD', voters => [ { firstname => 'F1', lastname => 'L1', }, { firstname => 'F2', lastname => 'L2', }, ], }; my $vars2 = { ed => 'ED', ad => 'AD', voters => [ { firstname => { name => 'F1' }, lastname => { name => 'L1' }, }, { firstname => { name => 'F2' }, lastname => { name => 'L2' }, }, ], }; my $t = Template::->new; $t->process(\$input, $vars); $t->process(\$input, $vars2);

Output:

<p>ed=ED ad=AD</p> <table> <tr><th>First</th><th>Last</th></tr> <tr> <td>F1</td> <td>L1</td> </tr> <tr> <td>F2</td> <td>L2</td> </tr> </table> <p>ed=ED ad=AD</p> <table> <tr><th>First</th><th>Last</th></tr> <tr> <td>HASH(0x7f8f68805630)</td> <td>HASH(0x7f8f688448b0)</td> </tr> <tr> <td>HASH(0x7f8f68844688)</td> <td>HASH(0x7f8f688446d0)</td> </tr> </table>

— Ken

Replies are listed 'Best First'.
Re^2: Dancer2 Template Toolkit interpolation
by cLive ;-) (Prior) on Dec 23, 2016 at 06:11 UTC
    Thanks for youe insights. In the end though, I worked out I had the wrong templating engine set in the config - knew it would be something simple :D