mirror of
https://github.com/helm/helm.git
synced 2026-08-04 15:10:47 +00:00
fix(helm): Set template context inside tpl function to outer function.
docs(helm): Added documentation about tpl function
This commit is contained in:
@@ -166,19 +166,32 @@ func (e *Engine) alterFuncMap(t *template.Template) template.FuncMap {
|
||||
|
||||
// Add the 'tpl' function here
|
||||
funcMap["tpl"] = func(tpl string, vals chartutil.Values) (string, error) {
|
||||
r := renderable{
|
||||
tpl: tpl,
|
||||
vals: vals,
|
||||
basePath, err := vals.PathValue("Template.BasePath")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Cannot retrieve Template.Basepath from values inside tpl function", tpl, err.Error())
|
||||
}
|
||||
|
||||
r := renderable{
|
||||
tpl: tpl,
|
||||
vals: vals,
|
||||
basePath: basePath.(string),
|
||||
}
|
||||
|
||||
println(vals.Table)
|
||||
|
||||
templates := map[string]renderable{}
|
||||
templates["aaa_template"] = r
|
||||
templateName, err := vals.PathValue("Template.Name")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Cannot retrieve Template.Name from values inside tpl function", tpl, err.Error())
|
||||
}
|
||||
|
||||
templates[templateName.(string)] = r
|
||||
|
||||
result, err := e.render(templates)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Error during tpl function execution for %q: %s", tpl, err.Error())
|
||||
}
|
||||
return result["aaa_template"], nil
|
||||
return result[templateName.(string)], nil
|
||||
}
|
||||
|
||||
return funcMap
|
||||
|
||||
Reference in New Issue
Block a user