-
-
Notifications
You must be signed in to change notification settings - Fork 190
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
unexpected "|" in template clause #290
Comments
Thanks for logging this, @estahn! That doesn't seem to be quite the right syntax, though there's still a bug. Using the built-in $ gomplate -i '{{define "foo"}}hello world{{end}}{{ template "foo" | js }}'
Error: template: <arg>:1: unexpected "|" in template clause But this succeeds: $ gomplate -i '{{define "foo"}}hello world{{end}}{{ template "foo" . | js }}'
hello world This should succeed, but doesn't: $ gomplate -i '{{define "foo"}}hello world{{end}}{{ template "foo" . | strings.ToUpper }}'
Error: template: <arg>:1:56: executing "<arg>" at <strings>: wrong type for value; expected string; got *main.Context So, clearly there's something missing 😉 |
Ok, this is a pretty widely-scoped bug. Essentially, I have a number of functions that accept only Interestingly, at first glance $ gomplate -i '{{define "foo"}}hello world{{end}}{{ template "foo" . | strings.Indent }}'
2018/04/18 20:39:19 Indent: invalid arguments This is because it takes All this to say - the fix for I'm on it - just need to step out for a quick jog and I'll try and get a fix drafted tonight or tomorrow 👍 |
Ok, further discovery - my reading of the template docs was way off... When rendering templates of the form $ gomplate -i '{{ define "T1" }}hello {{ . }}{{end}}{{template "T1" "world" | strings.ToUpper }}'
hello WORLD
$ gomplate -i '{{ define "T1" }}hello {{ .hello }}{{end}}{{template "T1" data.JSON `{"hello":"world"}` }}'
hello world So, based on all this, this isn't a bug in gomplate, but a simple syntax issue. I'd be nice to be able to handle many different kinds of input to the functions in the I'm going to close this now - feel free to re-open if you disagree 🙂 |
I feel that helps sort of with #291 , but don't see how it will help with the indentation of the output of |
I'm not sure this is possible with $ gomplate -i '{{ define "T1" }}{{ strings.Indent .width "." "hello world" }}{{ end -}}
{{ template "T1" data.YAML "width: 3" }}
{{ template "T1" data.YAML "width: 4" }}'
...hello world
....hello world Hope that helps! |
@hairyhenderson Thanks for the support and quick turnaround. 👍 |
🙇 |
The other approach I think (especially while including template files) is to use tmpl.Exec (that returns a string which can be piped to strings.Indent)
|
Template:
Error message:
Error: template: -:39: unexpected "|" in template clause
The text was updated successfully, but these errors were encountered: