collections.Dictionary
Returns a map created from the given key-value pairs.
- Syntax
- collections.Dictionary [VALUE...]
- Returns
- map[string]any
- Alias
- dict
Usage
The collections.Dictionary function returns a map created from the given key-value pairs. Specify the key-value pairs as individual arguments, alternating between keys and values. The function returns an error if the number of arguments is odd.
Each key must be a string or a slice of strings. Use a slice of strings to create a nested map, where each element of the slice is a key at the next level.
Call the function without arguments to create an empty map.
Examples
{{ $m := collections.Dictionary "a" 1 "b" 2 }}
{{ $m }} → map[a:1 b:2]Creating a nested map:
{{ $m := collections.Dictionary (slice "a" "b" "c") "value" }}
{{ $m }} → map[a:map[b:map[c:value]]]
{{ $m.a.b.c }} → valueCreating an empty map:
{{ $m := collections.Dictionary }}
{{ $m }} → map[]Last updated:
November 24, 2026
:
content: Apply style guide to collections functions (04f2e2939)
Improve this page