On Jan 17, 2004, at 22:50, 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 %]

If school_details is a hash, sort does this:


http://www.template-toolkit.org/docs/plain/Manual/ VMethods.html#Hash_Virtual_Methods

'Return a list of the keys, sorted alphabetically (sort) or numerically (nsort) according to the corresponding values in the hash.'

so n will be each of the keys.

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

You're trying to treat a hash as a list. I'd _expect_ to get one element as a result, the hash again, but what looks like is happening is you're implicitly calling the 'list' method:


'Returns the contents of the hash in list form. An argument can be passed to indicate the desired items required in the list: 'keys' to return a list of the keys (same as hash.keys), 'values' to return a list of the values (same as hash.values), or 'each' to return as list of (key, value) pairs (same as hash.each). When called without an argument it returns a list of hash references, each of which contains a 'key' and 'value' item representing a single key => value pair in the hash.'

..so you're getting hashes in n.

I don't know what you're expecting to happen. You could try the 'keys' vmethod, but you won't get the keys back in any sort of expected order.

.tom


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

Reply via email to