Search code examples
javastringtemplatestringtemplate-4

StringTemplate rendering map as literal value


Using org.stringtemplate.v4.ST I am trying to render this template:

$if(foo.map)$Foo Map: <foo.map.keys:{k | <k>: <foo.map.(k)>}; separator="\n"><br/>$endif$

When the st.render() method is invoked, this is printed out:

Foo Map: <foo.map.keys:{k | <k>: <foo.map.(k)>}; separator="\n"><br/>

Even though I have set the values in foo.map they are not printed out. How do I print the values instead of the template literal?


Solution

  • I didn't tried it out. But on the first view. Your delimiter is '$' for start and end. And not '<', '>'. So this should do the trick:

    $if(foo.map)$Foo Map: $foo.map.keys:{k | $k$: $foo.map.(k)$}; separator="\n"$<br/>$endif$