Prev
Returns the previous page in a site’s collection of regular pages, relative to the current page.
Syntax
PAGE.Prev
Returns
page.Page
Hugo determines the next and previous page by sorting the site’s collection of regular pages according to this sorting hierarchy:
The sorted page collection used to determine the next and previous page is independent of other page collections, which may lead to unexpected behavior.
For example, with this content structure:
content/
├── pages/
│ ├── _index.md
│ ├── page-1.md <-- front matter: weight = 10
│ ├── page-2.md <-- front matter: weight = 20
│ └── page-3.md <-- front matter: weight = 30
└── _index.mdAnd these templates:
layouts/section.html
{{ range .Pages.ByWeight }}
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}layouts/page.html
{{ with .Prev }}
<a href="{{ .RelPermalink }}">Previous</a>
{{ end }}
{{ with .Next }}
<a href="{{ .RelPermalink }}">Next</a>
{{ end }}When you visit page-2:
- The
Prevmethod points to page-3 - The
Nextmethod points to page-1
To reverse the meaning of next and previous you can change the sort direction in your site configuration, or use the Next and Prev methods on a Pages object for more flexibility.
Last updated:
March 5, 2025
:
content: Remove "related" array from function and method pages (2fcd21ee5)
Improve this page