# Conditionally displaying RSS Feed icons for tags based on feed availability

**URL:** <https://zola.discourse.group/t/conditionally-displaying-rss-feed-icons-for-tags-based-on-feed-availability/2530>\
**Category:** Support\
**Created:** [March 16, 2025, 3:11pm UTC](https://zola.discourse.group/t/conditionally-displaying-rss-feed-icons-for-tags-based-on-feed-availability/2530 "2025-03-16T15:11:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tzinm](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@tzinm](https://zola.discourse.group/u/tzinm)\
**Post date:** [March 16, 2025, 3:11pm UTC](https://zola.discourse.group/t/conditionally-displaying-rss-feed-icons-for-tags-based-on-feed-availability/2530/1 "2025-03-16T15:11:26Z")

</div>

Hey everyone!

I’m currently working on enhancing the tabi theme, maintained by @welpo, to include RSS feed icons for individual tags. During this process, I’ve encountered a scenario where some tags are associated with pages that don’t have a `date` field in their frontmatter. As a result, Zola doesn’t generate the `atom.xml` file for those tags, even when `feed = true` is set in the taxonomies within `config.toml`.

This discussion originated in the tabi repository: [GitHub Discussion #493](https://github.com/welpo/tabi/discussions/493#).

## Understanding the Behaviour

If a tag is only assigned to pages without a `date` field, clicking on its feed icon leads to a 404 page because the `atom.xml` file has not been generated. For example, accessing the feed for the tag **bash** , which is only associated with project pages that lack a `date` field, results in a 404 error.

Zola’s behaviour aligns with the [RSS specification](https://validator.w3.org/feed/docs/atom.html#requiredEntryElements), which requires that entries in an Atom feed must have a **date field**. This means that even when `feed = true` is enabled in `config.toml`, the absence of dated pages prevents the feed from being created.

## Possible Solution

From the discussion in the tabi repository, two key aspects need to be considered:

1. **Checking the global feed setting:**  
In Zola, the `feed = true` setting is part of the `[taxonomies]` configuration in `config.toml`, determining whether RSS feeds should be generated for a given taxonomy, such as tags. According to the documentation, the `list.html` file as well as the `single.html` file have access to the `taxonomy` variable which is of type `TaxonomyConfig` object. This value can be checked using the boolean type property named `feed`. However, this only controls feed generation. It doesn’t ensure that an `atom.xml` file will exist for every tag, as the file is only created if at least one associated page contains a `date` field in its frontmatter.

2. **Verifying that `atom.xml` has been generated:**  
Since Zola only generates an `atom.xml` file if at least one page under a tag contains a `date` field in its frontmatter, there is a need to check whether this condition is met before rendering the feed icon. The challenge is finding a way to perform this check within Zola’s templating system.

## Questions

- How can we check, within Zola’s templating system, whether at least one page associated with a tag contains a `date` field?
- Are there any alternative approaches within Zola that could help address this issue?

I appreciate any insights or suggestions from the community. Thanks!

---

<div class="post-metadata">

**Author:** ![alirezaalavi](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@alirezaalavi](https://zola.discourse.group/u/alirezaalavi)\
**Post date:** [March 17, 2025, 8:29am UTC](https://zola.discourse.group/t/conditionally-displaying-rss-feed-icons-for-tags-based-on-feed-availability/2530/2 "2025-03-17T08:29:38Z")

</div>

I think this is related to the problem that I also have, to be able to read files at compile time.  
if there is a function like get\_files(path) and get\_file(path) in zola, you can check if `atom.xml` actually exists or not. and then render accordingly.

I’m not good enough with rust to confidently do this, but I looked at the source code of zola and looked how `resize_image` function is defined and it seems pretty simple to add these functions into zola.

> [@Macro for image carousel](https://zola.discourse.group/t/macro-for-image-carousel/2529):
>
> Hi guys, I want to create a macro for image carousel, which takes the path of a directory, and renders the image of that directory in the carousel. I have created the macro with static images but I don’t know how I can read the filenames within a directory. this is how the simple carousel looks {% macro image\_carousel(directory\_path="") %} \<script type="text/javascript" defer src="/js/carousel.js"\>\</script\> \<div class="carousel"\> \<img loading="lazy" src="/images/screensho…

---

<div class="post-metadata">

**Author:** ![tzinm](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@tzinm](https://zola.discourse.group/u/tzinm)\
**Post date:** [March 20, 2025, 10:45pm UTC](https://zola.discourse.group/t/conditionally-displaying-rss-feed-icons-for-tags-based-on-feed-availability/2530/3 "2025-03-20T22:45:51Z")

</div>

After reviewing the documentation again, I found a potential solution using the [`get_taxonomy_term`](https://www.getzola.org/documentation/templates/overview/#get-taxonomy-term) global function.

This function retrieves a `term` from a specific `taxonomy`, requiring two parameters:

- `kind`: the taxonomy type.
- `term`: the term for which we want to retrieve data.

It returns a `TaxonomyTerm` object, which includes a `pages` field containing all the pages associated with the given term.

In `list.html`, we have access to the `taxonomy` variable (of type `TaxonomyConfig`), which contains the `name` field (corresponding to `kind`), as well as the `terms` variable, which is an array of `TaxonomyTerm` object. Based on this, the logic is as follows:

1. Iterate over the `terms` in `list.html`.
2. For each term, call `get_taxonomy_term`, passing `taxonomy.name` as `kind` and `term.name` as `term`, retrieving the `TaxonomyTerm` object.
3. Iterate over the `pages` field of the retrieved object and check if any of them contain the `date` field.
4. If at least one page has a `date`, display the feed icon.

Here is the implementation in Zola:

```auto
{%- for term in terms -%}
    {% if taxonomy.feed %}
        {% set taxonomy_term = get_taxonomy_term(kind=taxonomy.name, term=term.name) %}
        {% for page in taxonomy_term.pages %}
            {% if page.date %}
                {% set_global has_date = true %}
                {% break %}
            {% endif %}
        {% endfor %}
    {% endif %}
{%- endfor -%}

```

While this solution works in most cases, I encountered an issue when `term.name` contains special characters, such as accents. When passing a term like `"acción"`, the function fails with the following error:

```auto
Error: Reaseon: `get_taxonomy_term` received an unknown term: acción

```

I attempted to apply `slugify` to `term.name` before passing it to the function. However, this did not resolve the issue.

Could it be that `get_taxonomy_term` doesn’t correctly handle terms with special characters internally?
