Filtering by section does not work properly

I am having trouble generating a list of blog posts and projects on my index page.

I have 2 sections: blog and projects.

In /layout/index.html I have:

    {{- range (.Paginate (where site.RegularPages "Section" "blog" | first 3 )).Pages }}
        <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
    {{- end -}}

    {{- range (.Paginate (where site.RegularPages "Section" "projects" | first 3 )).Pages }}
        <li><a href="{{ .RelPermalink }}">{{ .Title }}</a></li>
    {{- end -}}

And this content directory.

β”œβ”€β”€ blog
β”‚   └──
└── projects
    └── looks like this:

title: 11


Same for, except with 2s instead of 1s.

So, with this configuration, I would expect my generated list to be something like:

- 11

- 22

However, I get this:

What am I doing wrong? If this is a bug, what can I do to work around it?

You are invoking .Paginate twice. See:

The .Paginator is static and cannot change once created.

Since you are only listing 3+3=6 pages, why paginate at all?

1 Like

Thank you!

You helped me come up with a solution:

{{- range where site.RegularPages "Section" "projects" | first 3 }}

I found the old code on some old thread and thought it was some kind of magic that’s supposed to just work. Anyway, the problem is now solved.

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