hugo/content/en/methods/page/Prev.md
Bjørn Erik Pedersen 9b0050e9aa Squashed 'docs/' content from commit 5c085a37b
git-subtree-dir: docs
git-subtree-split: 5c085a37b297bf12f59efeaae591418ec025c10d
2024-01-27 10:48:33 +01:00

1.2 KiB

title description categories keywords action toc
Prev Returns the previous page in a global page collection, relative to the given page.
related returnType signatures
methods/page/Next
methods/page/PrevInSection
methods/page/NextInSection
methods/pages/Prev
methods/pages/Next
page.Page
PAGE.Prev
true

The behavior of the Prev and Next methods on a Page object is probably the reverse of what you expect.

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.md

When you visit page-2:

  • The Prev method points to page-3
  • The Next method points to page-1

{{% note %}} Use the opposite label in your navigation links as shown in the example below. {{% /note %}}

{{ with .Next }}
  <a href="{{ .RelPermalink }}">Prev</a>
{{ end }}

{{ with .Prev }}
  <a href="{{ .RelPermalink }}">Next</a>
{{ end }}

Compare to Pages methods

{{% include "methods/_common/next-prev-on-page-vs-next-prev-on-pages.md" %}}