N00b question: Sort pages by weight

Hi all, I’m new to Zola but have experience with Twig and Hugo. Having a very embarrassing problem: I’m trying to loop over every page in Tera and sort them by weight, but I get an error. My code:

{% for page in pages|sort(attribute="weight") %}
  {# print page #}
{% endfor %}

I’m not sure what I’m doing wrong, and I couldn’t find any documentation that provided any more insight.

Thanks in advance!

If you say in the parent section that you want them sorted by weight (sort_by = "weight"), it will be sorted automatically.

Oh interesting, thanks for the reply. This will actually solve my current use case, but out of curiosity, is there a way to print pages with multiple sorts inside the same section?

For instance, say I’m using weighted sort plus another condition to print menu items (e.g. menu = true), and then in that same section print date sorted article pages in the main content.

If you don’t use pagination, you can just use something like:

{% for page in pages %}
  {% if page.extra.menu %}
    {{page.title}}
  {% endif %}
{% endfor %}