diff --git a/templates/templates.go b/templates/templates.go index 167554c15..d04ad6aeb 100644 --- a/templates/templates.go +++ b/templates/templates.go @@ -259,7 +259,15 @@ func (te templateExpander) ExpandHTML(templateFiles []string) (result string, re }() var buffer bytes.Buffer - tmpl, err := html_template.New(te.name).Funcs(html_template.FuncMap(te.funcMap)).Parse(te.text) + tmpl := html_template.New(te.name).Funcs(html_template.FuncMap(te.funcMap)) + tmpl.Funcs(html_template.FuncMap{ + "tmpl": func(name string, data interface{}) (html_template.HTML, error) { + var buffer bytes.Buffer + err := tmpl.ExecuteTemplate(&buffer, name, data) + return html_template.HTML(buffer.String()), err + }, + }) + tmpl, err := tmpl.Parse(te.text) if err != nil { return "", fmt.Errorf("Error parsing template %v: %v", te.name, err) } diff --git a/templates/templates_test.go b/templates/templates_test.go index 23e9babb3..5aff1d860 100644 --- a/templates/templates_test.go +++ b/templates/templates_test.go @@ -147,6 +147,12 @@ func TestTemplateExpansion(t *testing.T) { text: "{{ tableLink \"up\" }}", output: "/graph#%5B%7B%22expr%22%3A%22up%22%2C%22tab%22%3A1%7D%5D", }, + { + // tmpl. + text: "{{ define \"a\" }}x{{ end }}{{ $name := \"a\"}}{{ tmpl $name . }}", + output: "x", + html: true, + }, } time := clientmodel.Timestamp(0)