2017-02-26 22:23:06 -06:00

1.4 KiB

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
functions
dictionary
false
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 %}}