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

Add template function cat #1899

Closed
wants to merge 1 commit into from
Closed

Add template function cat #1899

wants to merge 1 commit into from

Conversation

digitalcraftsman
Copy link
Member

Cat returns the concatenated version of multiple
strings that are delimited by a separator.

Cat returns the concatenated version of multiple
strings that are delimited by a separator.
@bep
Copy link
Member

bep commented Feb 27, 2016

cat on Unix doesn't do this ... This looks like something we have already.

@digitalcraftsman
Copy link
Member Author

This looks like something we have already.

Hugo provides a delimit function. But it requires a list of strings. Out of the box it's not possible to create a slice in Go's template language (as far as I know). Cases like this one could be handled with cat, since cat doesn't requires as slice of strings. Instead it takes the strings as single arguments.

cat on Unix doesn't do this

Usually, cat concatenates the content of files in Unix and returns them to Stdout. I treated the file's content as string (as analogy). But we can change name / description if this PR isn't rejected.

@moorereason
Copy link
Contributor

Delimit can also take a map, so can you use dict on the first arg to delimit?

@digitalcraftsman
Copy link
Member Author

That's a clever workaround. The following example will output the same:

{{ delimit (dict "key1" "foo" "key2" "bar") ", " }}

You can achieve this already with built-in tools but everytime you've to add a key which isn't used at all. You need to make the tradeoff between potential redundancy and (in my eyes) a more elegant use.

@moorereason
Copy link
Contributor

True: the dict requires useless, unique keys.

I would rather see us add a slice template func instead of this cat proposal:

func slice(args ...interface{}) []interface{}

Use case:

{{ delimit (slice "foo" "bar") ", " }}

@digitalcraftsman
Copy link
Member Author

That sounds like a good compromise. I'll close this issue and open a new one for your suggested slice function.

@digitalcraftsman digitalcraftsman deleted the tplfunc/cat branch February 27, 2016 15:34
@digitalcraftsman
Copy link
Member Author

See #1902

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants