5

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 %}
6754534367
  • 5,123
  • 4
  • 17
  • 24
  • 1
    Why did you tag it with the [tag:tera] tag, when you ask about zola? – hellow Apr 25 '19 at 05:31
  • 1
    @hellow Zola uses Tera, a template engine for Rust and otherwise the post wouldn't have any visibility at all because it's just starting out. – 6754534367 Apr 25 '19 at 09:27
  • 1
    *"Zola uses Tera"* that combined with that the [tag:zola] is new is okay-ish. But because you use [tag:rust] gives it enough visbility I guess. Leave it for now :) – hellow Apr 25 '19 at 09:36

1 Answers1

1

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.

muhuk
  • 15,777
  • 9
  • 59
  • 98