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
text/template: arbitrary template picked on empty blocks #40186
Comments
There aren't any tests that cover this use case; it's always a So it's hard for me to tell if the current behavior is explicitly by design, or if it's an unintended behavior that we should fix. The feature was added in https://go-review.googlesource.com/c/go/+/14005/ in 2015, so I hope @adg @robpike @rogpeppe can chime in. |
Also, here's a playground link with source code that I found easier to understand: https://play.golang.org/p/ILdl-3v1edT |
I'm not sure what the confusion is here. If you define a block then it redefines the earlier template of the same name with the contents of the block. Maybe this is a documentation issue? |
The confusion on my part is whether this is working as intended, thus the documentation should be tweaked, or if it's an implementation bug like @bep says, and then we should fix the implementation to make |
If my issue above was a little long, I think it boils down to this: {{ block "empty" . }} {{ end }} Is currently not considered to be a valid template definition. However, this is: {{ define "empty" . }} {{ end }} |
What do you mean by "valid template definition"? It doesn't get defined? Btw I don't think this works with the
It should be
Can you boil it down to a tiny play.golang.org example to demonstrate what you mean? |
According to the documentation, it does:
(and yes, my example above had a cut and paste-error). So this: {{ block "empty" . }} {{ end }} Should be the same as:
But it isn't. |
These are the same: https://play.golang.org/p/-Wf47qTqKu1 What's the distinction you're drawing here? In your examples in the first comment I see template redefinitions - is that the source of confusion? The docs for
In this example we can see that by parsing a template definition of the same name effectively shadows the original one. I show it using both If I'm still not understanding you, can you please alter the example and share it here so that it demonstrates the problem you're seeing? Thanks. |
The distinction between an empty template defined separately or as part of a block definition. Your example does not resemble my example. |
Defining an empty template will not redefine an existing template, as per the docs on Parse (that I quoted earlier):
Again, I observe that If I'm still not understanding you, can you please alter my example and share it here so that it demonstrates the problem you're seeing? Thanks. |
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
This is a mistake. |
As far as I can tell, the label and bot worked as intended here. @adg asked a question in #40186 (comment). If you can answer it, we can reopen the thread. |
Ref. the documentation:
The program below prints:
The below is a common construct to create master/overlay constructs, and it's also common to leave the blocks empty and optional. I would expect
Empty: empty-foo|
to beEmpty:|
-- and not just pick an arbitrary template with the same name. I have added theEmpty2: |
to show that empty template defintions (e.g. whitespace only) works fine on its own.The text was updated successfully, but these errors were encountered: