Define map "literal" in template?

Is it possible to define a map literal (or rough equivalent) in Hugo’s templates?

I’d like to do something roughly equivalent to (pseudocode combining Go + JS syntax):

{{ $map := { "a": 123, "b": 456 } }}
{{ range $elem_key, $elem_val := $map }}
   {{ $elem_key }} -- {{ $elem_val }}
{{ end }}

What’s the correct syntax for defining $map in this case?

Note: I put “literal” in quotes because I read somewhere that Go doesn’t support map literals. The key point is that I want to just play around with the data structure all in a single template without having to worry (yet) about the real datasource.

Hi,

You can use a dict. Or a Scratch.

2 Likes

Ah, yes. Thanks (once again), @pointyfar!

I’d been searching for “map” and “hash” and neither word is present on the dict doc page, despite the return value being a map.