diff options
-rw-r--r-- | docs/templates.md | 4 | ||||
-rw-r--r-- | templater/templater.go | 8 |
2 files changed, 11 insertions, 1 deletions
diff --git a/docs/templates.md b/docs/templates.md index 6c44035d0967..32da205108de 100644 --- a/docs/templates.md +++ b/docs/templates.md @@ -72,13 +72,15 @@ right. Some template functions come from Go's standard library and are listed in the [Go documentation][]. In addition the functions declared by [sprig][] are -available in kontemplate, as well as three custom functions: +available in kontemplate, as well as five custom functions: * `json`: Encodes any supplied data structure as JSON. * `gitHEAD`: Retrieves the commit hash at Git `HEAD`. * `passLookup`: Looks up the supplied key in [pass][]. * `insertFile`: Insert the contents of the given file in the resource set folder as a string. +* `insertTemplate`: Insert the contents of the given template in the resource + set folder as a string. ## Examples: diff --git a/templater/templater.go b/templater/templater.go index e842daeba0a2..55b64766ce8c 100644 --- a/templater/templater.go +++ b/templater/templater.go @@ -205,6 +205,14 @@ func templateFuncs(c *context.Context, rs *context.ResourceSet) template.FuncMap return string(data), nil } + m["insertTemplate"] = func(file string) (string, error) { + data, err := templateFile(c, rs, path.Join(rs.Path, file)) + if err != nil { + return "", err + } + + return data.Rendered, nil + } m["default"] = func(defaultVal interface{}, varName string) interface{} { if val, ok := rs.Values[varName]; ok { return val |