hugo/docs/content/en/functions/collections/Dictionary.md
2024-06-21 09:41:24 +02:00

864 B

title description categories keywords action aliases
collections.Dictionary Returns a map composed of the given key-value pairs.
aliases related returnType signatures
dict
functions/collections/Slice
mapany
collections.Dictionary [VALUE...]
/functions/dict

Specify the key-value pairs as individual arguments:

{{ $m := dict "a" 1 "b" 2 }}

The above produces this data structure:

{
  "a": 1,
  "b": 2
}

To create an empty map:

{{ $m := dict }}

Note that the key can be either a string or a string slice. The latter is useful to create a deeply nested structure, e.g.:

{{ $m := dict (slice "a" "b" "c") "value" }}

The above produces this data structure:

{
  "a": {
    "b": {
      "c": "value"
    }
  }
}