An issue implementing .NextInSection

Hi there!

I am struggling to make the following work (paraphrased from my /layouts/news/single.html template):

    {{ .Content }} 
    {{ if .NextInSection }}
        <a href="{{ .NextInSection.RelPermalink }}" class="action-button">Next</a>
    {{ else }}
        <a href="{{ .FirstInSection.RelPermalink }}" class="action-button">First</a>

Issue 1:

{{ if .NextInSection }} never evaluates to true; it renders as .
On compile, I get the following error:

Error while rendering page news\ template: theme/news/single.html:34:20: executing "theme/news/single.html" at <.NextInSection.Perma...>: can't evaluate field Permalink in type *hugolib.Page

Issue 2:

It doesn’t seem that there is indeed a function such as .FirstInSection, so I am trying to figure out how to simulate the same functionality.

Can someone help?

OK, I seem to have solved Issue 1. I needed to use .PrevInSection to traverse posts, as it traverses in date order, not in the same sort order that I have displayed the content in, and my first post (as displayed) is actually the last. Issue two remains, how do I find the .Permalink for the last/first post, or the last/first post with a specified weight?

Hey there! Thanks a lot. Will give that a go and see what I can figure out.

1 Like