Go to content

Converting a HashMap into a nested listing in Freemarker

Published on

For the e-Alert we use Freemarker as templating engine. One of the new features of the next release will be a list of all subscribed categories and interests for the recipient.

All subscribed categories and interests from the database are inside a HashMap called userInterests. The names of the categories are the keys, a List of the names of the interests are the values. In the Freemarker template it looks like:

[#list userInterests.keySet() as category]
        [#list userInterests[category] as interest]

Freemarker converts this into the nested list of categories and interests. Eventually it will look like:

  • Information type
    • News
  • Subject
    • Content management
    • Open source