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

1

7

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 %}
Nutritive answered 24/4, 2019 at 21:13 Comment(3)
Why did you tag it with the tera tag, when you ask about zola?Bluh
@Bluh 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.Nutritive
"Zola uses Tera" that combined with that the zola is new is okay-ish. But because you use rust gives it enough visbility I guess. Leave it for now :)Bluh
L
3

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.

Lett answered 27/10, 2019 at 11:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.