diff --git a/pkg/tmpl/context_tmpl.go b/pkg/tmpl/context_tmpl.go index 7dcf4402..f49ccddf 100644 --- a/pkg/tmpl/context_tmpl.go +++ b/pkg/tmpl/context_tmpl.go @@ -87,17 +87,6 @@ func (c *Context) newTemplate() (*template.Template, error) { tmpl = tmpl.Option("missingkey=error") } - tpls, err := c.helperTPLs() - if err != nil { - return nil, err - } - for _, tpl := range tpls { - tmpl, err = tmpl.Parse(tpl.content) - if err != nil { - return nil, fmt.Errorf("failed to parse helper template %s: %v", tpl.name, err) - } - } - includedNames := make(map[string]int) // Add the 'include' function here so we can close over t. @@ -116,6 +105,18 @@ func (c *Context) newTemplate() (*template.Template, error) { return buf.String(), err } tmpl.Funcs(funcMap) + + tpls, err := c.helperTPLs() + if err != nil { + return nil, err + } + for _, tpl := range tpls { + tmpl, err = tmpl.Parse(tpl.content) + if err != nil { + return nil, fmt.Errorf("failed to parse helper template %s: %v", tpl.name, err) + } + } + return tmpl, nil } diff --git a/test/integration/test-cases/include-template-func/input/_helpers.tpl b/test/integration/test-cases/include-template-func/input/_helpers.tpl index e629445a..16681488 100644 --- a/test/integration/test-cases/include-template-func/input/_helpers.tpl +++ b/test/integration/test-cases/include-template-func/input/_helpers.tpl @@ -1,3 +1,3 @@ {{- define "echo" -}} -{{ .Echo }} +{{ .Echo | trim }} {{- end }} \ No newline at end of file diff --git a/test/integration/test-cases/include-template-func/input/nested/_helpers.tpl b/test/integration/test-cases/include-template-func/input/nested/_helpers.tpl index e61eb218..db6524d9 100644 --- a/test/integration/test-cases/include-template-func/input/nested/_helpers.tpl +++ b/test/integration/test-cases/include-template-func/input/nested/_helpers.tpl @@ -1,3 +1,3 @@ {{- define "echo" -}} -nested-{{ .Echo }} +nested-{{ .Echo | trim }} {{- end }} \ No newline at end of file diff --git a/test/integration/test-cases/include-template-func/input/values/_helpers.tpl b/test/integration/test-cases/include-template-func/input/values/_helpers.tpl index e629445a..16681488 100644 --- a/test/integration/test-cases/include-template-func/input/values/_helpers.tpl +++ b/test/integration/test-cases/include-template-func/input/values/_helpers.tpl @@ -1,3 +1,3 @@ {{- define "echo" -}} -{{ .Echo }} +{{ .Echo | trim }} {{- end }} \ No newline at end of file