]> Cypherpunks repositories - gostls13.git/commitdiff
text/template: explain better the semantics of ParseFiles
authorRob Pike <r@golang.org>
Tue, 23 Jun 2015 03:05:25 +0000 (13:05 +1000)
committerRob Pike <r@golang.org>
Tue, 23 Jun 2015 03:18:52 +0000 (03:18 +0000)
Documentation change only.

Fixes #11247.

Change-Id: Ib412de2d643292dbe42b56dee955bdb877aee81b
Reviewed-on: https://go-review.googlesource.com/11329
Reviewed-by: David Symonds <dsymonds@golang.org>
src/text/template/helper.go

index 3636fb54d697f635a9411e063f75c0a296482730..07d432bd3bdac00478a8505744db9375b4df841e 100644 (file)
@@ -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...)
 }