Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change subvariable in FreeMarker

Tags:

freemarker

Is there a way to change a subvariable within a hash or a container in a FreeMarker template? For example, suppose I had:

{"name":"Bob", "city":"Detroit", "state":"OH"}

and I want to change the state to "MI". How would I go about doing that? I know about the assign tag, but the documentation says "Note that only top-level variables can be created/replaced". I am unsure as to whether this means subvariables can't be replaced with the assign tag, or subvariables can't be replaced by any means.

like image 725
Elias Zamaria Avatar asked Dec 18 '22 07:12

Elias Zamaria


1 Answers

I figured out a simple way to do it:

<#assign hash = hash + {"state":"MI"}>
like image 87
Elias Zamaria Avatar answered May 03 '23 19:05

Elias Zamaria