An issue implementing .NextInSection

Hi there!

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

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

Issue 1:

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

Error while rendering page news\201610-new-website-launched.md: 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?

https://gohugo.io/templates/list#first-where-together

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

1 Like