Help with using Tera filters on arrays of pages

I seem to be having difficulty in grasping how to properly use Tera’s array filters on an array of pages in Zola.

For example, I am quite able to get the array of pages from current_section.pages which can be filtered with filter and then iterated using Tera’s for loops. A brief example being:

{% set current_section = get_section(path=current_path ~ "_index.md" | trim_start_matches(pat="/")) %}
{% set featured_articles = current_section.pages | filter(attribute="taxonomies.status", value=["en-vedette"]) %}
{% for p in featured_articles %}
{{ p.title }}
{% endfor %}

This will simply work as expected, giving us the title string of each page in the array. However, if I use a different filter – for example getting the first, last, or nth using the appropriate Tera filters on the array of current_section.pages – I seem to be unable to use the page [object] similarly. I get an error that the page variables are not found.

An example that generates an error being:

{% set current_section = get_section(path=current_path ~ "_index.md" | trim_start_matches(pat="/")) %}
{% set main_article = current_section.pages | nth(n=1) %}
{{ main_article.title }}

This will give me an error of Variable main_article.title not found in context while rendering 'index.html'. I can see that main_article is an [object], thus so far I am expecting it is a page object. However, it clearly is not the same type of object as the ones I am using when iterating with a for loop.

It’s easy enough for me to simply just use a for loop to get around this, but it would be much more elegant to be able to use the other Tera array filters.

What am I not understanding here? How can I properly use these other Tera array filters on an array of pages?

Any and all help is greatly appreciated!

I’m not sure it matters, but the Tera documentation does say nth counts from zero.

I do remember coming across a case where an expected member was missing from a page object, but I’ve had so many “ah ha” moments since I can’t be sure who was to blame (the wetware or the software). :yum: