Is there anything like .PrevInSection and .NextInSection, but for the root directory?

I’ve been enjoying using .PrevInSection and .NextInSection in my template to provide navigation links to the previous and next page in the current section (e.g. /content/cats/).

However, I want to do the exact same thing with the root “section” (e.g. /content/) and this seems to be very tricky to do. When I’m in the root “section” (not sure what it’s called in Hugo terminology), .PrevInSection and .NextInSection both seem to be empty as I suppose it’s not considered a section at all to Hugo.

.Prev and .Section do contain entries; however, they don’t ONLY contain pages in the root section, but also in sub sections as well. This means that if I use .Prev and .Next, I end up getting pages from /content/cats/ and /content/dogs/ showing up instead of only things that are directly in /content/.

Is there any way to just get the /content/ pages (immediate children) with prev/next?

Totally untested but if you give a certain Type to those pages you should be able to generate next/prev links from your template for those pages wrapped in a if eq .Type condition.

This works beautifully, thanks. I now have back and forward buttons just for my main pages only. I think it’s probably dependent on the page weights to properly order the pages so the root ones are all together (with no subsection pages mixed in), but it works.

The only problem I have now is that _index.md which gets rendered as index.html doesn’t show up in the .Prev/.Next list. Any idea how I could get that included?

The index page is special in Hugo. But you can call it in your template with {{ if .IsHome }}