mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-27 22:09:53 +02:00
Add dictionary function to be passed into a template
Allows templates to dynamically build maps. Example usage: Creating and passing a map to a subtemplate while in a range on the parent.
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
ccd83c3040
commit
3a27cefec1
@@ -50,6 +50,29 @@ e.g.
|
||||
|
||||
// Outputs Tags: tag1, tag2 and tag3
|
||||
|
||||
### dict
|
||||
Creates a dictionary (map[string, interface{}), expects parameters added in value:object fasion.
|
||||
Invalid combinations like keys that are not strings or uneven number of parameters, will result in an exception thrown
|
||||
Useful for passing maps to partials when adding to a template.
|
||||
|
||||
e.g. Pass into "foo.html" a map with the keys "important, content"
|
||||
|
||||
{{$important := .Site.Params.SomethingImportant }}
|
||||
{{range .Site.Params.Bar}}
|
||||
{{partial "foo" (dict "content" . "important" $important)}}
|
||||
{{end}}
|
||||
|
||||
"foo.html"
|
||||
|
||||
Important {{.important}}
|
||||
{{.content}}
|
||||
|
||||
|
||||
or Create a map on the fly to pass into
|
||||
|
||||
{{partial "foo" (dict "important" "Smiles" "content" "You should do more")}}
|
||||
|
||||
|
||||
|
||||
### echoParam
|
||||
Prints a parameter if it is set.
|
||||
|
Reference in New Issue
Block a user