join
Joins the elements of a slice into a single string.
Every element must be a string; a non-string element is an error. The separator defaults to a newline when it is omitted or empty.
[]anyanystring[]anyno argumentsstringJoins the elements of a slice into one string with the given separator.
Given
{"tags": ["coffee", "sale", "new"]}Template
{{ tags | join:',' }}Result
coffee,sale,newJoins the elements with a pipe separator, a common way to render a slice as a single delimited field.
Given
{"parts": ["foo", "bar", "baz"]}Template
{{ parts | join:' | ' }}Result
foo | bar | bazJoins the elements of a slice with a multi-character separator.
Given
{"words": ["one", "two", "three"]}Template
{{ words | join:' - ' }}Result
one - two - threeJoins the elements of a slice on a newline when no separator is given.
Given
{"items": ["a", "b", "c"]}Template
{{ items | join }}Result
a
b
cJoins a two-element slice, placing each element on its own line since the default separator is a newline.
Given
{"items": ["line one", "line two"]}Template
{{ items | join }}Result
line one
line twoJoins a single-element slice, leaving it as just that element with no separator added.
Given
{"items": ["only"]}Template
{{ items | join }}Result
onlyReports an error when a slice element is not a string.
Given
{"nums": ["1", 2, "3"]}Template
{{ nums | join:',' }}Result
error: failed to render template: failed to render variable token 'nums': modifier "join": function failed to apply: join expected an array of strings, got int at index 1