Determine array length

Hi everybody,
the topic tells my question already.

I want to list all my categories (defined in the front matter) and separate them all with a pipe or a comma - but not after the last element of course.

So i want to put that separator after every element, except the last one. How do i accomplish that?

thx. :slight_smile:

p.s: It would be great if one could check if the actual element in an array is the first or the last one.

i just found another approach to my problem:

instead of appending a separator, i just prepend it - starting with the second element in an array.
here is the code:

{{ range $i, $e := .Params.categories}}{{if $i}}, {{end}}<a href="">{{$e}}</a>{{end}}
1 Like

There’s actually a delimit function that will do that when 0.13 is released.

1 Like