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:
NotZippy
2015-10-02 08:30:21 -07:00
committed by Bjørn Erik Pedersen
parent ccd83c3040
commit 3a27cefec1
3 changed files with 63 additions and 0 deletions

View File

@@ -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.