views:

2885

answers:

1

Freemarker has two collection datatypes, lists and hashmaps Is there a way to iterate over hashmap keys just as we do with lists?

so if i have a var with data lets say

user : {
  name : "user"
  email : "[email protected]"
  homepage : "http://nosuchpage.org"
}

i would like t print all the user's properties with their value. This is invalid, but the goal is clear:

<#list user.props() as prop>
  ${prop} = ${user.get(prop)}
</#list>
+5  A: 

You use the built-in keys function, e.g. this should work:

<#list user?keys as prop>
    ${prop} = ${user.get(prop)}
</#list>
skaffman
thanx a lot, now i could find the doc for it
tzador