-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: text/template: allow multiple actions within {{}}
#46588
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 |
It's unclear why we would take on the added complexity here when there is already a way to write that with more {{ }}. |
This proposal has been added to the active column of the proposals project |
Why not use For the specific case of a simple if expression, Hugo has
That may solve your usecase, but note that it eagerly evaluates both alternatives. |
I agree that the implementation and specification cost is large for a small benefit. It is not a goal of the template language to be as convenient as possible, but rather just to provide a safe link between macro expansion and Go values. |
Here are a few examples of complex logic encapsulated in templates that might help this discussion:
Most of the embedded templates in Hugo are having a huge amount of template code where it is harder to read with the mustaches around them. |
I have written a lot of frontend logic in my Hugo templates myself. I don't find the mustaches to be a big deal, particularly for HTML where whitespace is not significant and gets minimized away. Before you could reassign variables (!), it was a pain to have to use a Hugo scratch for logic, but now that you can, it's basically just a simple dynamic language for processing frontend tags from my point of view, like PHP but more internally consistent. |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
What version of Go are you using (
go version
)?1.16.4
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOOS="darwin"
What did you do?
The desire is to be able to place multiple commands in a Go text template. We already have newlines supported ( #29770 ). If we get multiple commands using any separator, we can simplify templates with multiple mustaches one after the other.
An example using Hugo (with a semi-colon as a separator, can be anything):
equivalent to:
The text was updated successfully, but these errors were encountered: