Get_taxonomy return value

It is not clear in the documentation what the get_taxonomy function returns.

We might want to add that it returns an object with kind and items.

Here is some code I used to find it out:

{% for t in config.taxonomies %}
<div>
    Taxonomy<br>
    Name: {{t.name}}<br>
    {% set taxonomy = get_taxonomy(kind=t.name) %}
    get_taxonomy: {{taxonomy}}<br>
    kind (taxonomy config): {{taxonomy.kind}}<br>
    items: {{taxonomy.items}}, length: {% set length = taxonomy.items | length %}{{length}}<br>
    {% for item in taxonomy.items %}
        {{ item.name }}
        <br>
    {% endfor %}
</div><br>
{% endfor %}

If someone wants to browse the whole taxonomy tree:

{% for t in config.taxonomies %}
<ul>
    {% set taxonomy = get_taxonomy(kind=t.name) %}
    <li>{{taxonomy.kind.name}} ({{ taxonomy.items | length }})</li>
    <ul>
    {% for item in taxonomy.items %}
        {% set url = get_taxonomy_url(kind=taxonomy.kind.name, name=item.name) %}
        <li><a href="{{url}}">{{ item.name }}</a> ({{ item.pages | length }})</li>
        <ul>
            {% for p in item.pages %}
                <li><a href="{{p.permalink}}">{{p.title}}</a></li>
            {% endfor %}
        </ul>
    {% endfor %}
    </ul>
</ul>
{% endfor %}

I’ve already added https://github.com/getzola/zola/pull/1038/commits/cb198ab597de787f4cf8b313df19cb57d5bf4859 to the next branch

1 Like

Sorry, I’m usually reading the documentation from the website, thanks for your answer :slight_smile: