rusttemplate-enginezolatera

How can I iterate over the posts of a section using Zola?


I tried the following, which I found in the Zola documentation but it didn't render anything. The Tera docs weren't rewarding either.

{% for post in section.pages %}
  <h1><a href="{{ post.permalink }}">{{ post.title }}</a></h1>
{% endfor %}

Solution

  • The correct way to iterate over a paginated section is as following:

    {% for post in paginator.pages %}
      <h1><a href="{{ post.permalink }}">{{ post.title }}</a></h1>
    {% endfor %}
    

    paginator is described in the Templates section under Pagination: getzola.org/documentation/templates.

    A paginated section gets the same section variable as a normal section page minus its pages. The pages are instead in paginator.pages.