Setup Taxonomy Templates for Blog Tags in Zola
Zola uses taxonomies to group pages together. I wanted to give tags to every blog post I write and be able to list all posts related to a tag.
The documentation of Zola on taxonomies is pretty clear. But there is no example given of how to setup a page listing all tags or a page showing all pages with a certain tag.
The key to build such pages is given by the taxonomies documentation in the template section. It states that Zola will look up the following, taxon-specific files in the templates directory:
$TAXONOMY_NAME/single.html
$TAXONOMY_NAME/list.html
if they are not found, it will attempt to fall back on the following generic template files:
taxonomy_single.html
taxonomy_list.html
Take a look at the variables passed to those templates by Zola and then it should be clear how to build those templates.
Very simple examples for both templates:
<!--list.html-->
{% extends "base.html" %}
{% block content %}
<ul>
{% for t in terms %}
<li><a href="{{ t.path }}">{{ t.name }}</a></li>
{% endfor %}
</ul>
{% endblock content %}
<!--single.html-->
{% extends "base.html" %}
{% block content %}
{% for page in term.pages %}
<ul>
<li><a href="{{ page.permalink | safe }}">{{ page.title }}</a></li>
</ul>
{% endfor %}
{% endblock content %}
I found the post Setting up blog tags in Zola by Abitha K Thyagarajan helpful in getting things running for my own site.