Commit 009517e0 authored by Rob Pike's avatar Rob Pike

html/template: add DefinedTemplates to html/template

It is not important to add, since it's only used for creating an error message,
but for consistency in the API between text/template and html/template
it should be provided here.

The implementation just calls the one in text/template.

Fixes #13349.

Change-Id: I0882849e06a58f1e38b00eb89d79ac39777309b2
Reviewed-on: https://go-review.googlesource.com/17172Reviewed-by: 's avatarAndrew Gerrand <adg@golang.org>
parent 656a732a
......@@ -80,7 +80,7 @@ func (t *Template) escape() error {
defer t.nameSpace.mu.Unlock()
if t.escapeErr == nil {
if t.Tree == nil {
return fmt.Errorf("template: %q is an incomplete or empty template%s", t.Name(), t.text.DefinedTemplates())
return fmt.Errorf("template: %q is an incomplete or empty template%s", t.Name(), t.DefinedTemplates())
}
if err := escapeTemplate(t, t.text.Root, t.Name()); err != nil {
return err
......@@ -143,6 +143,13 @@ func (t *Template) lookupAndEscapeTemplate(name string) (tmpl *Template, err err
return tmpl, err
}
// DefinedTemplates returns a string listing the defined templates,
// prefixed by the string "defined templates are: ". If there are none,
// it returns the empty string. Used to generate an error message.
func (t *Template) DefinedTemplates() string {
return t.text.DefinedTemplates()
}
// Parse parses a string into a template. Nested template definitions
// will be associated with the top-level template t. Parse may be
// called multiple times to parse definitions of templates to associate
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment