Back to Hugo

collections.Dictionary

docs/content/en/functions/collections/Dictionary.md

0.161.1554 B
Original Source

Specify the key-value pairs as individual arguments:

go-html-template
{{ $m := dict "a" 1 "b" 2 }}

The above produces this data structure:

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

To create an empty map:

go-html-template
{{ $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.:

go-html-template
{{ $m := dict (slice "a" "b" "c") "value" }}

The above produces this data structure:

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