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: Better doc for ParseFiles and Execute behaviour. #11247

Closed
siritinga opened this issue Jun 17, 2015 · 1 comment
Closed

text/template: Better doc for ParseFiles and Execute behaviour. #11247

siritinga opened this issue Jun 17, 2015 · 1 comment
Assignees
Milestone

Comments

@siritinga
Copy link

@siritinga siritinga commented Jun 17, 2015

Hello.

I recently spent some time trying to figure why a template with Funcmaps would work with Parse() but not with ParseFiles() when using Execute (instead of ExecuteTemplate with the name).

I found the answer in Stack Overflow http://stackoverflow.com/questions/10199219/go-template-function but the question also appeared in golang-nuts, for example here https://groups.google.com/forum/#!topic/golang-nuts/CI9WdC_sk00 and here https://groups.google.com/forum/#!topic/golang-nuts/vmZHHfLsH8M

Please consider if it should be better documented to make it less error-prone for inexperienced users.

Thank you.

@gobijan
Copy link

@gobijan gobijan commented Jun 22, 2015

I came here because I also wanted to open an issue about this. This API is not really developer friendly. Maybe one should change the semantics too and not only the docs. It feels wrong to name the most outer template again in template new just to add a funcMap via .Funcs.

// This is what currently works
tmpl := template.Must(template.New("layout.html.go").Funcs(funcMap).ParseFiles("tmpl/layout.html.go","tmpl/index.html.go"))

One has to explicitly name the outer template. This should at least be documented :)

@robpike robpike closed this in f2662f2 Jun 23, 2015
@mikioh mikioh modified the milestones: Go1.5, Unplanned Jun 23, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
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
6 participants
You can’t perform that action at this time.