Render the Keys and Values From a Map in Freemarker

Posted on Dec 24, 2009 (last modified Jun 1, 2021)

Render the values of a Map

The following code snippet shows how to get the values of a Map (e.g. HashMap) from within a Freemarker template.

<#assign m = myMap> <#assign values = m?values> <ul> <#list values as myObject> <li>$\{myObject.myPropery\}</li> </#list> </ul>

Render the keys of a Map

You can do a similar thing with the keys of a map as shown below.

<#assign m = myMap> <#assign keys = m?keys> <ul> <#list keys as key> <li>$\{key\} </#list> </ul>