Skip to content
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, html/template: document Funcs must be called before Parse #18971

Closed
zwass opened this issue Feb 7, 2017 · 5 comments
Closed

text/template, html/template: document Funcs must be called before Parse #18971

zwass opened this issue Feb 7, 2017 · 5 comments
Assignees
Milestone

Comments

@zwass
Copy link

@zwass zwass commented Feb 7, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

Go 1.6+

What operating system and processor architecture are you using (go env)?

Any

What did you do?

https://play.golang.org/p/SeHjhOvCFZ (html/template)
https://play.golang.org/p/EeVfv5_IcQ (text/template)

What did you expect to see?

I would expect that both success() and fail() successfully write the string "foo" to stdout

What did you see instead?

The fail function panics with the error, panic: template: :1: function "foo" not defined. If possible, it would feel much more consistent for both of these functions to succeed. If that is not possible, updating the documentation to reflect the need for custom functions to be defined before the template is loaded would be very helpful to confused users.

See, for example:

@zwass zwass changed the title text/template & html/template text/template & html/template: Custom functions must be defined before template is loaded Feb 7, 2017
@zwass zwass changed the title text/template & html/template: Custom functions must be defined before template is loaded text/template & html/template: Custom functions must be defined before template is parsed Feb 7, 2017
@minux minux changed the title text/template & html/template: Custom functions must be defined before template is parsed text/template, html/template: document custom functions must be defined before template is parsed Feb 7, 2017
@minux minux added this to the Go1.9 milestone Feb 7, 2017
@gopherbot
Copy link

@gopherbot gopherbot commented Feb 7, 2017

CL https://golang.org/cl/36425 mentions this issue.

@paranoiacblack paranoiacblack self-assigned this Feb 7, 2017
@paranoiacblack
Copy link
Contributor

@paranoiacblack paranoiacblack commented Feb 7, 2017

Just adding myself as a reviewer here; I'm not sure how to find the github account of the CL creator.

@odeke-em
Copy link
Member

@odeke-em odeke-em commented Feb 7, 2017

Ping @gulyasm if am not mistaken.

@gulyasm
Copy link
Contributor

@gulyasm gulyasm commented Feb 7, 2017

@paranoiacblack Yes, it's me.

@rsc rsc assigned robpike and unassigned paranoiacblack Feb 10, 2017
@rsc rsc changed the title text/template, html/template: document custom functions must be defined before template is parsed text/template, html/template: document Funcs must be called before Parse Feb 10, 2017
@gopherbot
Copy link

@gopherbot gopherbot commented Mar 21, 2017

CL https://golang.org/cl/38413 mentions this issue.

@gopherbot gopherbot closed this in 5c5a106 Mar 21, 2017
@golang golang locked and limited conversation to collaborators Mar 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.