-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: add a slice function to the predefined global functions #30153
Comments
Would three-index slice expressions be supported, such as Do you have any data or research to back the need/popularity of such a builtin function? We do have |
Change https://golang.org/cl/161762 mentions this issue: |
I don't think the three-index form is a real use case for templates.
I didn't do any research before, just came up with my real use case. I use templates extensively, and many times find it missing for slicing/substring strings and slices. Little searching in the web, led to find these few links:
Anyway, I don't mind leave it open and see what others think about this. |
This is so easy to do with a user-defined function that I don't see the need to build it in. |
It does seem hard to justify having |
Per discussions with @golang/proposal-review, it seems like we should do this. @robpike any final thoughts? |
The justification is that the template language is not Go. I still think it's a rare usage in a template and easily done by a user-defined function, but if the sentiment is against me, so be it. But the template language really isn't Go. |
Accepting per further discussion with @robpike and @golang/proposal-review. |
These are great news. Just for my curiosity, how does the "proposal-review" work? is it public? |
@a8m more info can be found in https://github.com/golang/proposal/blob/master/README.md |
This has been moved to utils/. Just for fun, not sure where this went: golang/go#30153
I'm suggesting to add a function named
slice
to the predefined global functions under thetext/template
package that will mimic the slice expression in Go.Calling
slice
returns the result of slicing its first argument by the following arguments.Thus
{{ slice x 1 3 }}
is, in Go syntax, x[1:3]. Each sliced item must be a string, slice, or array.The text was updated successfully, but these errors were encountered: