mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
53 lines
864 B
Markdown
53 lines
864 B
Markdown
---
|
|
title: collections.Dictionary
|
|
description: Returns a map composed of the given key-value pairs.
|
|
categories: []
|
|
keywords: []
|
|
action:
|
|
aliases: [dict]
|
|
related:
|
|
- functions/collections/Slice
|
|
returnType: mapany
|
|
signatures: ['collections.Dictionary [VALUE...]']
|
|
aliases: [/functions/dict]
|
|
---
|
|
|
|
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 slice`. 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"
|
|
}
|
|
}
|
|
}
|
|
```
|