On Sat, Jan 17, 2004 at 04:50:42PM -0600, D. Martin wrote:
> Hi everyone,
> 
> This is my first post to the list. I am very new to TT2.
> 
> My problem is this, I am iterating over a hash and this:
> 
> [% FOREACH n = school_details.sort %]
>        <tr><td>[% n %]</td><td>[% school_details.$n %]</td></tr>  
> [% END %]
> 
> works exactly as expected.
> 
> But take the sort out like so:
> 
> [% FOREACH n = school_details %]
>       <tr><td>[% n %]</td><td>[% school_details.$n %]</td></tr>  
> [% END %]
> 
> And the output looks like this:
> 
> HASH(0x877d21c)  
> HASH(0x877d1ec)  
> HASH(0x877d1bc)  
> HASH(0x877d1a4)
> 
> Presumably the address in Perl's symbol table.
> 
> What am I doing wrong?

Simply iterating over a hash without using one of the vmethods is
(as you've seen) pretty pointless. You actually want to use a
vmethod like "keys" or "sort" (which TT actually interprets as
"keys.sort").

So you probably want to rewrite your second example as:

[% FOREACH n = school_details.keys %]
      <tr><td>[% n %]</td><td>[% school_details.$n %]</td></tr>
[% END %]

hth,

Dave...

-- 
  New .sigs
  Running in please parse

_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to