findTaxonomy() doesn't find pages

Hello, in a project I’m trying to get the index of the current page in the collection of all pages with the taxonomy {‘series’: ‘lp’}, ordered by date.

But I can’t even get to that collection of pages.

{{ var_dump(taxonomy.findTaxonomy({'series': 'lp'})) }}

Prints NULL, though the taxonomy of a particular page can be accessed by page.taxonomy.series.

My user/config/site.yaml contains taxonomies: [category, tag, series].

Any idea what could be going wrong here? Thanks!

May be so:

{% for page in taxonomy.findTaxonomy({'series': 'lp'}) %}
{{ page.title }}
{% endfor%}
---

@stanislav’s code should work. I just confirmed by testing with my own taxonomy type ‘tag’ and it performed as expected. I would try with the cache turned off as it could be related to that.

Okay, thank you for your answers!

I used the Twig tag above incorrectly, {% do var_dump() %}did print out something.

The for loop works indeed. I just hoped to create a concise macro using PHP array methods to get to the index of a certain page in an ordered, taxonomy-based Grav collection, but that didn’t work out.
Now I have this solution for my problem:

{% macro getIndex(page, series, variables) %}
  {% set i = 0 %}
  {% for colpage in variables.taxonomy.findTaxonomy({'series': 'series'}).order("date", "asc") %}
  {% set i = i + 1 %}
    {% if colpage.path == page.path %}
      {{i}}
    {% endif %}
  {% endfor %}
{% endmacro %}

_context has to be passed to variables to allow the macro to access the taxonomy variable.

It uses an ordinary counter, but it works. If you know a more elegant solution, I’d love to hear :slight_smile: