Move first item on an array at the end

Hello,

I have an array of N items, and I want to move the first one at the end.
Any idea?

Thanks,
Jeremie

Perhaps something like:

{{ $item := slice "one" "two" "three" "four" }}
{{ range after 1 $item }}
...
{{ end }}
{{ range first 1 $item }}
...
{{ end }}

Have a look at the doc about iterating over a map, slice or array and how to slice an array with after.

Also you may render the 1st item last with index

{{ $slice := slice "a" "b" "c" }}
{{ range after 1 $slice }}
...
{{ end }}
{{ index $slice 0 }} => a
1 Like

Thanks a lot. I merged them both back after, as I had to use the same range on the whole array afterwards.

{{ $first := first 1 $item }}
{{ $last := after 1 $item }}
{{ $all := $last | append $first }}
2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.