Add ability to iterate over key/value pairs in a map
jgm opened this issue · 0 comments
jgm commented
Something like
$forpairs(meta)$
- $meta.key$: $meta.value$
$endforpairs$
And when forpairs
is applied to a regular array, key
should be set to the index (starting with 1). This would allow us to create numbered lists, for example:
$forpairs(items)$
$item.key$. $item.value.name$ ($item.value.price$)
$endforpairs$
An alternative approach would be to provide some general mechanism for turning a map into an array with key/value objects:
$for(meta/pairs)$
$it.key$ = $it.value$
$endfor$
$meta/pairs:partial()$
Thinking ahead, the /
could perhaps be reserved for filters that alter a variable:
$date/iso8601$
$name/uppercase/underscores$