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

Ability to join list of items into string with separator #143

Closed
alexandrem opened this issue May 19, 2017 · 2 comments
Closed

Ability to join list of items into string with separator #143

alexandrem opened this issue May 19, 2017 · 2 comments

Comments

@alexandrem
Copy link

Something missing in the string functions is to be able to do a traditional join to make a string out of a list of items with a defined delimiter character.

nameservers:
  - "8.8.8.8"
  - "8.8.4.4"

Template:

{{ (datasource "config").nameservers | join " " }}

output => "8.8.8.8 8.8.4.4"

@hairyhenderson
Copy link
Owner

@alexandrem thanks for taking the time to log this!

There is a join function, but I seem to have missed documenting it 🤦‍♂️. It unfortunately won't work in a pipeline like that (mostly because I didn't think about that usage, and instead chose to follow strings.Join's signature more literally).

But you can use it like:

$  gomplate -i '{{ $a := `[1, 2, 3]` | jsonArray }}{{ join $a "-" }}'
1-2-3

So your template could look like:

{{ join (datasource "config").nameservers " " }}

I've documented it in 8a45646 just now.

@alexandrem
Copy link
Author

Great thanks :)

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

No branches or pull requests

2 participants