-
Notifications
You must be signed in to change notification settings - Fork 18k
text/template: Template tree produced by template.Clone
is not in a clean state
#56409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
cc @robpike |
Does the bug occur with text/template alone? Here your test uses html/template, which is a large wrapper around text/template. It would be good to know where the problem truly arises. |
In the test project, I switched from importing |
Please provide a complete executable example. |
The full testing project code can be checked here: https://github.com/kidlj/blog |
I'm sorry but that's a large program with 55 external dependencies, and runs as a web server. For best results when asking for help with issues, it's best to provide a short, self-contained source file that compiles into a single binary that demonstrates the issue. |
Sure, sorry for the inconvenience. I found that I misunderstood how template parsing works while preparing a new smaller demonstration project for this issue. The truth is if the overlay template( Close. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
To make Go html/template inherit base template properly, every time executing an end template I make a copy via
template.Clone
of the full template tree, hoping it in a clean state, then add the desired end template to the cloned template tree and execute it. It almost works well, except that when a{{block "FOO" .}}{{end}}
is defined in the base template, but the corresponding named block is not{{define}}
-ed in the end executing template, the execution result may contain the content of block FOO defined in other templates that should not be executed.The clone and execution process is as follows:
And the base layout template is as follows:
When the
blog.html
template that inheritslayout.html
and defines blockfeed
is executed, it works fine(that producesfeed
block contents):But when the
index.html
template that also inheritslayout.html
but does not define blockfeed
is executed, the execution result also contains the content of blockfeed
, which seems like come fromblog.html
.The execution result:
In short, in the static blog project, I want
blogs.html
andblog.html
to have the feed link produced, but not having it on theindex.html
page.The full project code can be checked here: https://github.com/kidlj/blog
What did you expect to see?
Template tree produced by
template.Clone
is in a clean state that doesn't generate contents from blocks that have not been defined.What did you see instead?
Template tree produced by
template.Clone
generates block contents that are defined elsewhere not being executed.The text was updated successfully, but these errors were encountered: