keys
A sequence that contains all the lookup keys in the hash.
<#assign myHash = { "name": "mouse", "price": 50 }> <#list myHash?keys as k> ${k} </#list>
name price
Note that not all hashes support this (ask the programmer if a certain hash allows this or not).
Since hashes do not define an order for their sub variables in
general, the order in which key names are returned can be arbitrary.
However, some hashes maintain a meaningful order (ask the programmer
if a certain hash does that or not). For example, hashes created
with the above {...}
syntax preserve the same order as you have specified the sub
variables.
To list both the keys and the values, you can use
<#list attrs as key,
value>...<#list>
; see the list
directive.
values
A sequence that contains all the variables (the values in the key-value pairs) in the hash.
<#assign myHash = { "name": "mouse", "price": 50 }> <#list myHash?values as v> ${v} </#list>
mouse 50
Note that not all hashes support this (ask the programmer if a certain hash allows this or not).
As of the order in which the values are returned, the same
applies as with the keys
built-in; see there.
Furthermore, it's not guaranteed that the order of the values
corresponds to the order of the keys returned by the
keys
build-in.
To list both the keys and the values, you can use
<#list attrs as key,
value>...<#list>
; see the list
directive.