From f2662f2c938f2f9fd21067169b2aaec89f8d0e9f Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 23 Jun 2015 13:05:25 +1000 Subject: [PATCH] text/template: explain better the semantics of ParseFiles Documentation change only. Fixes #11247. Change-Id: Ib412de2d643292dbe42b56dee955bdb877aee81b Reviewed-on: https://go-review.googlesource.com/11329 Reviewed-by: David Symonds --- src/text/template/helper.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/text/template/helper.go b/src/text/template/helper.go index 3636fb54d6..07d432bd3b 100644 --- a/src/text/template/helper.go +++ b/src/text/template/helper.go @@ -26,8 +26,8 @@ func Must(t *Template, err error) *Template { } // ParseFiles creates a new Template and parses the template definitions from -// the named files. The returned template's name will have the (base) name and -// (parsed) contents of the first file. There must be at least one file. +// the named files. The returned template's name will have the base name and +// parsed contents of the first file. There must be at least one file. // If an error occurs, parsing stops and the returned *Template is nil. func ParseFiles(filenames ...string) (*Template, error) { return parseFiles(nil, filenames...) @@ -36,6 +36,11 @@ func ParseFiles(filenames ...string) (*Template, error) { // ParseFiles parses the named files and associates the resulting templates with // t. If an error occurs, parsing stops and the returned template is nil; // otherwise it is t. There must be at least one file. +// Since the templates created by ParseFiles are named by the base +// names of the argument files, t should usually have the name of one +// of the (base) names of the files. If it does not, depending on t's +// contents before calling ParseFiles, t.Execute may fail. In that +// case use t.ExecuteTemplate to execute a valid template. func (t *Template) ParseFiles(filenames ...string) (*Template, error) { return parseFiles(t, filenames...) } -- 2.50.0