Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
We don't bite newbies here... much
 
PerlMonks  

Re^7: Perl CGI and Template Toolkit

by Eliya (Vicar)
on Jan 04, 2012 at 16:34 UTC ( #946250=note: print w/ replies, xml ) Need Help??


in reply to Re^6: Perl CGI and Template Toolkit
in thread Perl CGI and Template Toolkit

When you refer to something like item_hoh in the template, this is a key in the hash, not the name of the hash itself (TT2 knows nothing about the name — the hashref could also be anonymous).  This isn't any different from using flat hashes to define/set TT2 variables, btw.

The solution is to just wrap another hash around it, e.g. an anonymous one (in my example above I used a named one, $HoH):

... TmplParams => { item_hoh => \%item_hoh },

The curlies create an anonymous hash(ref), and the value of the entry keyed by "item_hoh" is the ref to your hash %item_hoh.  The name of the latter is irrelevant.  In case you need to pass more top-level items (like the item_hoh), just add further entries in the anon hash.


Comment on Re^7: Perl CGI and Template Toolkit
Select or Download Code
Re^8: Perl CGI and Template Toolkit
by Perobl (Beadle) on Jan 04, 2012 at 18:58 UTC

    Wow, thank you so much for the lesson. I didn't know that. You have been incredibly helpful, and I can't thank you enough :)

    I'm so glad I can show this data in a clean table format!

    Thank you PerlMonk!!!

      You promised a free lunch.



      holli

      You can lead your users to water, but alas, you cannot drown them.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (13)
As of 2014-04-17 18:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (453 votes), past polls