Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: Dancer2 Template Toolkit interpolation by kcott
in thread Dancer2 Template Toolkit interpolation by cLive ;-)

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2022-12-02 07:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?