mirror of
https://github.com/gohugoio/hugo.git
synced 2026-09-02 19:52:38 +00:00
1.4 KiB
1.4 KiB
title, linktitle, description, godocref, workson, date, publishdate, lastmod, categories, tags, signature, workson, hugoversion, relatedfuncs, deprecated, aliases, needsexamples
| title | linktitle | description | godocref | workson | date | publishdate | lastmod | categories | tags | signature | workson | hugoversion | relatedfuncs | deprecated | aliases | needsexamples | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| dict | dict | Creates a dictionary `(map[string, interface{})` that expects parameters added in a value:object fashion. | 2017-02-01 | 2017-02-01 | 2017-02-26 |
|
|
false | true |
title: dict
linktitle: dict
description: Creates a dictionary (map[string, interface{}) that expects parameters added in a value:object fashion.
godocref:
workson: []
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2017-02-26
categories: [functions]
tags: [dictionary]
signature:
workson: []
hugoversion:
relatedfuncs: []
deprecated: false
aliases: []
needsexamples: true
dict creates a dictionary (map[string, interface{}) that expects parameters added in a value:object fashion.
Invalid combinations---e.g., keys that are not strings or an uneven number of parameters---will result in an exception being thrown. dict is especially useful for passing maps to partials being added to a template.
For example, the following snippet passes a map with the keys "important, content" into "foo.html"
{{% code file="dict-example.html" %}}
{{$important := .Site.Params.SomethingImportant }}
{{range .Site.Params.Bar}}
{{partial "foo" (dict "content" . "important" $important)}}
{{end}}
{{% /code %}}
These keys can then be called in foo.html as follows:
Important {{.important}}
{{.content}}
dict also allows you to create a map on the fly to pass into your partial templates
{{% code file="dict-create-map.html" %}}
{{partial "foo" (dict "important" "Smiles" "content" "You should do more")}}
{{% /code %}}