Skip to content

text/template: document redefinition of templates #17360

@icza

Description

@icza

Go home page, Go 1.7.1.

Package text/template and html/template provide the same interface. But the documentation of text/template.Parse() and html/template.Parse() are different.

text/template.Parse() leaves out an important fact that it is an error to redefine a non-empty template. html/template.Parse() contains this important fact. But they work the same way.

I believe when {{block}} action was added in Go 1.6 and redefining of templates got allowed, only the doc of html/template.Parse() was updated but not text/template.Parse().

Example code that triggers this error:

template.Must(template.New("").Parse(`{{block "A" "a"}}a{{end}}{{define "A"}}b{{end}}`))

Playground link with text/template: https://play.golang.org/p/PY3zLcCFiu

Playground link with html/template: https://play.golang.org/p/UeQk4D3tcB

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions