HUGO
Menu
GitHub 87548 stars Mastodon

Next

返回頁面集合中給定頁面的下一個頁面。

Syntax

PAGES.Next PAGE

Returns

page.Page

Hugo 根據此排序層次結構對頁面集合進行排序來確定 下一個上一個 頁面:

字段 優先級 排序方向
weight 1 降序
date 2 降序
linkTitle 3 降序
path 4 降序

用於確定 下一個上一個 頁面的已排序頁面集合獨立於其他頁面集合,這可能會導致意外行為。

例如,使用此內容結構:

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

以及這些模板:

layouts/section.html
{{ range .Pages.ByWeight }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}
layouts/page.html
{{ $pages := .CurrentSection.Pages.ByWeight }}

{{ with $pages.Prev . }}
  <a href="{{ .RelPermalink }}">上一個</a>
{{ end }}

{{ with $pages.Next . }}
  <a href="{{ .RelPermalink }}">下一個</a>
{{ end }}

當您訪問 page-2 時:

  • Prev 方法指向 page-3
  • Next 方法指向 page-1

要反轉 下一個上一個 的含義,您可以將 Reverse 方法鏈接到頁面集合定義:

layouts/page.html
{{ $pages := .CurrentSection.Pages.ByWeight.Reverse }}

{{ with $pages.Prev . }}
  <a href="{{ .RelPermalink }}">上一個</a>
{{ end }}

{{ with $pages.Next . }}
  <a href="{{ .RelPermalink }}">下一個</a>
{{ end }}

Last updated: January 1, 0001
Improve this page