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

Local Newline behavior isn't consistent with the docs #901

Closed
max-sixty opened this issue Jul 17, 2020 · 3 comments · Fixed by #906
Closed

Local Newline behavior isn't consistent with the docs #901

max-sixty opened this issue Jul 17, 2020 · 3 comments · Fixed by #906

Comments

@max-sixty
Copy link

max-sixty commented Jul 17, 2020

I imagine this is something I'm doing incorrectly. Running some of the examples locally, I don't see the same result as the docs. Any idea what the cause could be?

Here are a couple of examples:

https://docs.gomplate.ca/functions/strings/#examples-7

$ gomplate -i '{{ range ("foo:bar:baz" | strings.SplitN ":" 2) }}{{.}}{{end}}'
foobar:baz

# docs:
foo
bar:baz

https://docs.gomplate.ca/functions/strings/#examples-6

$ gomplate -i '{{range ("Bart,Lisa,Maggie" | strings.Split ",") }}Hello, {{.}} {{end}}'
Hello, Bart Hello, Lisa Hello, Maggie

# docs:
Hello, Bart
Hello, Lisa
Hello, Maggie

I tried on both bash and fish. I'm using gomplate version 3.7.0 on MacOS.

In lieu of the newlines not being added, can I add them myself? Adding \n causes those characters rather than a newline to appear.

Thanks!

@hairyhenderson
Copy link
Owner

Hi @max-sixty - thanks for logging this!

Your behaviour is correct, the docs are wrong. To get the behaviour you want, you are indeed correct, you need to add a \n. There's a few ways to do this that I can think of off the top of my head:

  1. you could simply add a newline character inside the template block (I think this is what I intended in the docs):
$ gomplate -i '{{ range ("foo:bar:baz" | strings.SplitN ":" 2) }}{{.}}
{{end}}'
foo
bar:baz
  1. you could output a \n character in a template directive:
$ gomplate -i '{{ range ("foo:bar:baz" | strings.SplitN ":" 2) }}{{.}}{{ "\n" }}{{end}}'
foo
bar:baz
  1. you could use print to print both the element and the \n in the same command:
$ gomplate -i '{{ range ("foo:bar:baz" | strings.SplitN ":" 2) }}{{ print . "\n" }}{{end}}'
foo
bar:baz

Either way, thanks again, this is a docs bug! 😅

@hairyhenderson
Copy link
Owner

Fixed in #906! The docs site should be up-to-date within the next couple of minutes.

@max-sixty
Copy link
Author

Great, thanks @hairyhenderson !

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

Successfully merging a pull request may close this issue.

2 participants