3

I've got a map of city names => distance-from-origin.

I'd like to use a partial with this map, and create something like so:

<ul>
<li>city1: distance1</li>
<li>city2: distance2</li>
<li>city3: distance3</li>
</ul>

What is the canonical way to do this with StringTemplate?

Thanks.

Alex Baranosky
  • 48,865
  • 44
  • 102
  • 150

1 Answers1

5
<ul>
$amap.keys:{k | <li>$k$: $amap.(k)$</li>}$
</ul>
Alex Baranosky
  • 48,865
  • 44
  • 102
  • 150
Terence Parr
  • 5,912
  • 26
  • 32
  • Ahhh!!!! got it, I guess I can't use hyphens in StringTemplate variable names. Thanks for the help. – Alex Baranosky Dec 14 '10 at 05:12
  • Note that in ST4 the default is to iterate over keys (rather than values as in ST3), so, the 'amap.keys' should be simply 'amap'. – phreed Sep 29 '22 at 17:00