feat: include func support more template functions (#1277)

This commit is contained in:
yxxhero 2024-01-09 14:33:50 +08:00 committed by GitHub
parent e6141e9004
commit 3576e7d36b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 14 deletions

View File

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

View File

@ -1,3 +1,3 @@
{{- define "echo" -}}
{{ .Echo }}
{{ .Echo | trim }}
{{- end }}

View File

@ -1,3 +1,3 @@
{{- define "echo" -}}
nested-{{ .Echo }}
nested-{{ .Echo | trim }}
{{- end }}

View File

@ -1,3 +1,3 @@
{{- define "echo" -}}
{{ .Echo }}
{{ .Echo | trim }}
{{- end }}