Sections not working as expected

I have the following structure in my content directory.

├── hug
│   └── index.md
├── links
│   ├── 2024-05-27-link1.md
│   ├── 2024-05-28-link2.md
│   ├── 2024-05-29-link3.md
│   ├── 2024-06-11-link4.md
│   └── 2024-06-18-link5.md
└── posts
    └── my-first-post.md

In my layout index.html file if have the following two blocks.

<div>
    <h1>Blog</h1>
    {{- range (.Paginate ( where site.RegularPages "Section" "posts" ) ).Pages }}
    <div>
        <a href="{{.Permalink}}">{{ .Title }}</a>
    </div>
    {{- end}}
</div>
<div>
    <h1>Links</h1>
    {{ range (.Paginate ( where site.RegularPages "Section" "links" ) ).Pages }}
    <div>
        <a href="{{.Permalink}}">{{ .Title }}</a>
    </div>
    {{ end}}
</div>

I would expect that the first block outputs all content from posts directory and the second block all content from links. Nevertheless, both blocks output only the one entry from posts.

But outputting the sections on the other hand produces exactly two entries using the following.

<div>
    <h1>Sections</h1>
    {{ range .Site.Sections }}
    <li><a href="{{ .Permalink }}">{{ .Title }}</a></li>
    {{ end }}
</div>

Even though I’m surprised that hug is completely ignored for both cases.

What am I missing here?

Thanks.

https://gohugo.io/templates/pagination/

image

1 Like

Thank you. Now that I’ve thought more about it, it totally makes sense that only one pagination per page is possible.
I my case (as I’m only beginning with Hugo) I was under the false impression that using pagination would be the best approach for my use-case. But now I realized that I can simply use range like this.

{{ range first 10 ( where site.RegularPages "Section" "links" ) }}
<div>
    <a href="{{.Permalink}}">{{ .Title }}</a>
</div>
{{ end}}

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.