This seems like a good idea.
If it becomes a base function, then it would be a good optimization
target resolving to a simple JS for..in loop when compiled to JS.
How useful would people find it if some kind of destructuring (
http://wiki.ecmascript.org/doku.php?id=harmony:destructuring ) were
allowed where $key appears in Tom's example?
So
{foreach [ $key, $value ] in properties( $map )}
...
{/foreach}
I think a more flexible option
{foreach $pair in keyValues($map)}
Key: {$pair.name} -
Value: {$pair.value}
<br />
{/foreach}
This will allow the use of templates for handling data with unknown structure
Andrey
There is no iteration order specified for JavaScript objects, but
EcmaScript harmony will probably specify insertion order within each
prototype chain layer which is the same as LinkedHashMaps in java.
Whould only own properties be returned in JS for compatibility with Java?
Is there an official solution for this or is it still a case of rolling our own?I want to be able to build a form based on an arbitrary map as per the above.e.g. something like:{foreach $key in keys($myMap)}{$key} = {value($myMap, $key)}{/foreach}Seems like a pretty fundamental thing so I'm a little surprised it's not there by default and this thread is a tad old.The keys($map) function seems to exist and works under normal circumstances, but not within a foreach, and I can't see anything that I could use for the 'value' part.