stringtemplatestringtemplate-4

How can I iterate over the keys and values of a String Template 4 Map?


In StringTemplate 4, the default behavior for iteration is to iterate over the keys instead of the values, which was the behavior in version 3.

I can not find the syntax for how to iterate over the keys and values at the same time for version 4.

Can someone post an example of the syntax?


Solution

  • You can use indirect property referencing to get the value for the key in the current iteration. Is this what you mean?

    <myMap.keys:{k | <k> maps to <myMap.(k)>}; separator="\n">
    

    prints:

    Jake maps to Dog
    Finn maps to Human