Jump to first post if .Next is nil

Hey there!

So my problem is that I try to loop though a list of posts and just use the .Next variable for navigation. And since .Next returns nil when there is no next post, I am searching for a way to jump back to the first post.

{{ if .NextInSection }}
   <a href="{{ .NextInSection.Permalink }}" class="wrapper">
         <b>Next</b> Project
         {{ .NextInSection.Title }}
{{ end }}

This is what I have so far and I am really grateful for some help, thanks!

To clarify, you want to jump to the first page in the current section?

Untested, but you could do something like:

{{ if .NextInSection }}
{{ else }}

    {{ range last 1 .CurrentSection.Pages }}
        {{ .Permalink }}
    {{ end }}

{{ end }}

Yeah, exactly!

And it works perfectly, thanks a lot! Appreciate your time :3

Have a greate day!

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