Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Dancer2 Template Toolkit interpolation

by kcott (Archbishop)
on Dec 20, 2016 at 09:22 UTC ( #1178180=note: print w/replies, xml ) Need Help??

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);


<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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1178180]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (1)
As of 2022-11-28 04:00 GMT
Find Nodes?
    Voting Booth?