]> Cypherpunks repositories - gostls13.git/commitdiff
html/template: add DefinedTemplates to html/template
authorRob Pike <r@golang.org>
Mon, 23 Nov 2015 20:43:17 +0000 (12:43 -0800)
committerRob Pike <r@golang.org>
Mon, 23 Nov 2015 22:11:16 +0000 (22:11 +0000)
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/17172
Reviewed-by: Andrew Gerrand <adg@golang.org>
src/html/template/template.go

index f0609ca6350bbf70b7f5d238ca4f2daa44df85a3..22d103026b100124713e850dd57ec1e326330319 100644 (file)
@@ -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