On Thu, Feb 27, 2025 at 1:04 PM Rory Campbell-Lange <r...@campbell-lange.net> wrote: > > The docstring for [html|text]/template.Funcs is as follows > > package template // import "html/template" > > func (t *Template) Funcs(funcMap FuncMap) *Template > Funcs adds the elements of the argument map to the template's > function map. > It must be called before the template is parsed. It panics if a value > in > the map is not a function with appropriate return type. However, it is > legal to overwrite elements of the map. The return value is the > template, > so calls can be chained. > > (The html version has the addition of "However"!). > > It wasn't obvious to me that to "overwrite elements of the map" one could call > Funcs with a funcMap of just those funcs that should be replaced, as shown in > https://go.dev/play/p/LWRmEL9XZce, rather than having to re-add all the funcs. > > Although this might be more obvious to experienced gophers, I suggest the > following addition to the docs: > > ...it is legal to overwrite elements of the map. For example, a func > registered with the name "x" before a template t is parsed might be > replaced after parsing the template as follows: > > t.Funcs(template.FuncMap{"x": strings.ToUpper}) > > The return value...
Another approach would be to add an example. Want to send a patch? Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWh0%3DB2gnA7XxvxN3rV3R%3D5BmTOsMbdZoP-XK5YoaJsJA%40mail.gmail.com.