Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I iterate over the terms in a taxonomy outside the list.html using Zola?

I've found out you can use

{% set posts = get_taxonomy(kind="posts") %}

to retrieve a taxonomy but I'm clueless how to iterate over the terms of the taxonomy in for example single.html of this taxonomy.

I tried things like the following, but I get:

"Tried to iterate using key value on variable 'posts', but it is missing a key"

{% set posts = get_taxonomy(kind="posts") %}
{% for term in posts %}
  <li class="list__item">
    <a href="{{ term.permalink }}">
      {{ term.name }}
    </a>
  </li>
{% endfor %}
like image 498
6754534367 Avatar asked Nov 07 '22 18:11

6754534367


1 Answers

get_taxonomy returns a struct with keys items & kind. You can debug using:

{% set posts = get_taxonomy(kind="posts") %}

<code>{{ posts.kind | json_encode(pretty=true) }}

{{ posts.items | json_encode(pretty=true) }}</code>

kind seems to have TaxonomyConfig structure and each element in items seems to have TaxonomyTerm structure.

like image 62
muhuk Avatar answered Nov 22 '22 17:11

muhuk