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: Functions are evaluated immediately and #16125

aarondl opened this issue Jun 20, 2016 · 1 comment

text/template: Functions are evaluated immediately and #16125

aarondl opened this issue Jun 20, 2016 · 1 comment


Copy link

@aarondl aarondl commented Jun 20, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go version 1.6.2 linux/amd64
  2. What operating system and processor architecture are you using (go env)?
    Ubuntu 16.04 Xenial - Linux, amd64
  3. What did you do?
    If possible, provide a recipe for reproducing the error.
    A complete runnable program is good.
    A link on is best.
  4. What did you expect to see?
    I expected the function toupper to be passed as an argument to map and for the output of the program to be like this one
  5. What did you see instead?
template: :1:10: executing "" at <toupper>: wrong number of args for toupper: want 1 got 0

It seems like toupper is evaluated as soon as it's seen, which breaks because it's meant to be an argument to the map function.

Copy link

@adg adg commented Jun 20, 2016

That's how template functions work. When they appear by name, they are invoked. They can't be passed as values within templates.

You can, however, pass the function as data, as you can see in this edited version of your first example:

@adg adg closed this Jun 20, 2016
@golang golang locked and limited conversation to collaborators Jun 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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