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: weird template block parameters precedence #33265

Closed
sylr opened this issue Jul 24, 2019 · 1 comment
Closed

text/template: weird template block parameters precedence #33265

sylr opened this issue Jul 24, 2019 · 1 comment

Comments

@sylr
Copy link

sylr commented Jul 24, 2019

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

$ go version
go1.12.7. 

Does this issue reproduce with the latest release?

Yes

What did you do?

https://play.golang.org/p/zPTLk2G-iAP

I'd like to gzip and base64 the output of the template so I've written this:

{{- define "pwet" }}
My string
{{- end}}
{{ template "pwet" . | stringToGzipedBase64 }}

This seems to be syntactically right but the way it's interpreted is not what I expected

{{ template "pwet" . | stringToGzipedBase64 }} // What I wrote
{{ template "pwet" (. | stringToGzipedBase64) }} // How it's interpreted by the parser
{{ (template "pwet" .) | stringToGzipedBase64 }} // How I think it should be interpreted 
@beoran
Copy link

beoran commented Jul 25, 2019

The syntax for the template statement is specified in https://golang.org/pkg/text/template:

{{template "name"}}
	The template with the specified name is executed with nil data.

{{template "name" pipeline}}
	The template with the specified name is executed with dot set
	to the value of the pipeline.

This means that {{template "pwet" . | stringToGzipedBase64}} is indeed interpreted as {{ template "pwet" (. | stringToGzipedBase64) }}, because the template key word cannot send it's output to a pipeline, only take it's input from one.

So the behavior we are seeing is as specified. Unfortunately, what you are trying to do, that is, capture the result of a template statement is not supported yet. Maybe it should be, but for the moment your example is working as expected.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants