feat: include func support more template functions (#1277)
This commit is contained in:
parent
e6141e9004
commit
3576e7d36b
|
|
@ -87,17 +87,6 @@ func (c *Context) newTemplate() (*template.Template, error) {
|
||||||
tmpl = tmpl.Option("missingkey=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)
|
includedNames := make(map[string]int)
|
||||||
|
|
||||||
// Add the 'include' function here so we can close over t.
|
// 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
|
return buf.String(), err
|
||||||
}
|
}
|
||||||
tmpl.Funcs(funcMap)
|
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
|
return tmpl, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
{{- define "echo" -}}
|
{{- define "echo" -}}
|
||||||
{{ .Echo }}
|
{{ .Echo | trim }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
{{- define "echo" -}}
|
{{- define "echo" -}}
|
||||||
nested-{{ .Echo }}
|
nested-{{ .Echo | trim }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
{{- define "echo" -}}
|
{{- define "echo" -}}
|
||||||
{{ .Echo }}
|
{{ .Echo | trim }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
Loading…
Reference in New Issue