Davide
Davide

Reputation: 602

Freemarker - How to put variables in hashmap?

I searched the web to find how to add some entries into an existing hashmap.

Consider this code:

<#assign foo={'bar':'go'}>

I want to add a new entry and have something like this:

foo={'bar':'go','new':'entry}

How can I do that?

Upvotes: 1

Views: 2460

Answers (1)

Davide
Davide

Reputation: 602

Using concatenation:

<#assign foo=foo+{'new':'entry'}>

print the hashmap:

<#list foo?keys as k>
    ${k}: ${foo[k]} <br>
</#list>

The result is exactly what you want:

bar: go
new: entry

D.

Upvotes: 2

Related Questions