How to get the rest of the range when using limit?

Hi all!

What would be the simplest way of getting “the rest of the items”? I.e. I’m looping thru my pages with a limit, but as a last link in in the list id like to display a “…and X more posts” link. How would i do that?

{{ range first 3 .Pages }}
    <a href="{{ .URL }}">{{ .Title }}</a>,
{{end}}
<a href"">...and X more pages</a>

Try this

Worked like a charm!

If you know the total number:

{{ range last 4 .Pages }}
    <a href="{{ .URL }}">{{ .Title }}</a>,
{{end}}
<a href"">...and X more pages</a>

I ended up doing like this:

{{ range first 3 .Pages }}
		<a href="{{ .URL }}">{{ .Title }}</a>,
		{{end}}

		{{ $rest := .Pages | symdiff (first 3 .Pages) }}

		{{ if $rest }}
		och <a href="{{ .URL }}">{{len $rest}} sidor till</a>
		{{end}}
1 Like

just realized a little problem, on the last round in the range i dont want to output the "," sign. Is there something like a loop variable i Go so that I can detect if the range loop is on the last iteration?

Checkout the delimit function

1 Like

ah! thanx!!

Could you post the completed solution for others to learn? Thanks!