Skip to content

text/template: clarify comment and docs for AddParseTree #34695

@greywolve

Description

@greywolve

There's an incorrect (and misleading) comment here:

// If the name is the name of this template, overwrite this template.
	nt := t
	if name != t.name {
		nt = t.New(name)
	}

It's probably mean't to be "If the name isn't...", but that's still not easy to read, and should potentially just be dropped? (It's fairly obvious what's going on)

The docs could be made more accurate instead:

AddParseTree adds parse tree for template with given name and associates it with t.
If the template does not already exist, it will create a new one.
If the template does exist, it will be replaced.

Should potentially be:

AddParseTree adds parse tree for template with given name and associates it with t.
If the template does not already exist, it will create a new one.
If the template does exist, it will be replaced, unless the given name matches the template's name.

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.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions