Debian Codegraph @

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

raw
1 ---
2 title: collections.Dictionary
3 description: Returns a map created from the given key-value pairs.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: [dict]
9 returnType: map[string]any
10 signatures: ['collections.Dictionary [VALUE...]']
11 aliases: [/functions/dict]
12 ---
13
14 Specify the key-value pairs as individual arguments:
15
16 ```go-html-template
17 {{ $m := dict "a" 1 "b" 2 }}
18 ```
19
20 The above produces this data structure:
21
22 ```json
23 {
24 "a": 1,
25 "b": 2
26 }
27 ```
28
29 Note that the `key` can be either a `string` or a `[]string`. The latter is useful to create a deeply nested structure, e.g.:
30
31 ```go-html-template
32 {{ $m := dict (slice "a" "b" "c") "value" }}
33 ```
34
35 The above produces this data structure:
36
37 ```json
38 {
39 "a": {
40 "b": {
41 "c": "value"
42 }
43 }
44 }
45 ```
46
47 To create an empty map:
48
49 ```go-html-template
50 {{ $m := dict }}
51 ```