weearc
February 13, 2024, 8:28am
1
Hi, I’m quite new to hugo. When creating a new layout archives
for it, I’d like to create a paginator for this page.
By using:
{{ $pages:= where site.RegularPages "Type" "in" site.Params.mainSections }}
It will get myself a page.Pages
variable.
But using:
{{ $paginator := .Paginate ($pages) 10 }}
It will get a $paginator
with value nil
. How can I build this paginator and can use {{ range }}
to go through it?
You are trying to paginate a page collection from a single page template.
https://gohugo.io/templates/pagination/#list-paginator-pages
Build a section stub, then target a list template.
In the next release, trying to paginate from an unsupported page kind will generate an error message:
error calling Paginate: pagination not supported for this page: kind: “page”, path: “/posts/post-11”, file: “/home/user/project/content/posts/post-11.md”
weearc
February 15, 2024, 8:38am
3
Sorry for late reply. Currently I’ve got the directory structure like this:
~/hugo-blog/content
❯ tree .
.
├── about.md
├── frlink.md
├── posts
│ ├── 2018-06-09.md
│ └── why-I-keep-out-zhihu.md
└── search.md
Does that mean I need to create _index.md
under /content/posts/
with the following frontmatter ?
title: Archive
url: 'archives/'
weearc
February 15, 2024, 8:43am
4
Oh it seems working as expected. Thank you a lot.
system
Closed
February 17, 2024, 8:43am
5
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.