text/template: add "else with" like "else if" #57646
However, no such "else with" counterpart exists:
Which would be very useful:
Currently, we must do the nesting that the else/if doc mentions:
This gets tiresome.
Mixing the two would also be useful:
The text was updated successfully, but these errors were encountered:
This adds no functionality, it is just a convenience. One may argue that it should be done for consistency, and it's not difficult although every change has costs (and for templates, they are doubled because of html/template). I am not convinced it is worth doing but I am not adamant.
It's just a convenience for if/else too.
This is real code:
Compare that to:
The difference might seem trivial if you're used to only touching templates occasionally or superficially, but it's a big quality of life improvement for those who spend hours writing non-trivial programs in templates, like authors of Hugo themes/modules.
or you could format your existing code like this
@seankhliao there's no sane template formatter (e.g.: https://github.com/NiklasPor/prettier-plugin-go-template) that would format the template source the way you suggest, and throwing a way automatic template formatting is not something anyone would want to do.
I agree with proposal. It should be of tremendous value (save lots of end user time) compared to the time spent on implementing it. I suspect that the people who say "thumbs down" to this are people who really don't spend any amount of time writing Go templates.