How to paginate a subdirectory?

I want templates/index.html to paginate through content/blog

├── content
│   ├── blog
│   │   ├──
│   │   └──
│   ├── comments.js
│   └── main.js
├── sass
│   └── aspenuwu.scss
├── templates
│   ├── base.html
│   ├── index.html
│   └── page.html

The documentation is not clear about how to do this, though.

You can make blog a transparent = true (Section | Zola) section and set pagination on a root instead. I think it should work?

Hey there, I was trying to do the same thing and came across your question in a search. I have a similar directory structure as you:

├── config.toml
├── content
│   ├──
│   └── posts
│       ├──
│       ├──
│       └──

In my index.html template, I put the following code:

{% block content %}
<h2>Latest Posts</h2>
    {% set section = get_section(path="posts/") %}
    {% for page in section.pages %}
    <li><a href="{{ page.permalink | safe }}">{{ page.title }}</a></li>
    {% endfor %}
{% endblock content %}

With this, I was able to iterate through the lists of posts without having to use transparent = true. With your directory structure, if you changed posts to blog it should accomplish the same thing:

    {% set section = get_section(path="blog/") %}
    {% for page in section.pages %}

With my code, I was only trying to iterate through the list of blog posts rather than paginate, but I hope it may help in some way. Huge caveat, today is my first day using Zola and I do not have any experience with Rust. I’m experimenting with migrating from Hugo. Hope that helps!

1 Like

I stumbled across the same problem: I have a /content/blog section also, and want templates/index.html to paginate over it. Doing a get_section(path="blog/") doesn’t get you a paginator. It has a property pages though, over which you can iterate.

The comment by Zola’s author keats with transparent = true in the located in the blog section was the most helpful one so far. Now I have a paginator. Everything seems fine. And it actually is.

But, one caveat for me: I had pages like,, etc. under /content, which are now also used for the paginator. Implementing some filter logic didn’t work, because of date and sort_by issues - leaving out some pages in the middle while having a paginate_by leads to ugly results.

I ended up with all my pages in its own section: /content/pages, which led to a cleaner template implementation.