NextInSection
Syntax
PAGE.NextInSection
Returns
page.Page
The behavior of the PrevInSection
and NextInSection
methods on a Page
object is probably the reverse of what you expect.
With this content structure:
content/
├── books/
│ ├── _index.md
│ ├── book-1.md
│ ├── book-2.md
│ └── book-3.md
├── films/
│ ├── _index.md
│ ├── film-1.md
│ ├── film-2.md
│ └── film-3.md
└── _index.md
When you visit book-2:
- The
PrevInSection
method points to book-3 - The
NextInSection
method points to book-1
{{ with .NextInSection }}
<a href="{{ .RelPermalink }}">Previous in section</a>
{{ end }}
{{ with .PrevInSection }}
<a href="{{ .RelPermalink }}">Next in section</a>
{{ end }}
With the PrevInSection
and NextInSection
methods, the navigation sort order is fixed, using Hugo’s default sort order. In order of precedence:
- Page weight
- Page date (descending)
- Page linkTitle, falling back to page title
- Page file path if the page is backed by a file
For example, with a page collection sorted by title, the navigation sort order will use Hugo’s default sort order. This is probably not what you want or expect. For this reason, the Next and Prev methods on a Pages object are generally a better choice.