HUGO
News Docs Themes Community GitHub

collections.Dictionary

Returns a map composed of the given key-value pairs.

Syntax

collections.Dictionary [VALUE...]

Returns

map[string]any

Alias

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. 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"
    }
  }
}