Count the archives items


I’d like show the archives section in sidebar only if archives have a length > 0, like related pages (in Quark theme for example)

How I filter this in sidebar template?


@pmoreno, are you talking about the future2021 theme?

Hello @b.da

Actually, it is a question related to any theme, but in this case it is about the Editorial theme. This theme has a sidebar like Future2021 and like Quark, where some blocks are located, depending on whether the plugins are installed or not (feeds, relatedpages, archives, taxonomylist, etc).

In this specific case, if the archives plugin is enabled, the text “Archives” appears and below the archives by month. But if you are not on the blog or item page, only the text “Archives” is displayed.


I would like the “Archives” header to not appear if there are no files to display (just like the RelatedPages plugin does). So far I have only managed to prevent it from being displayed by filtering by template type. Example:

{# Show Archives if plugin is enabled #}
         {% if config.plugins.archives.enabled and (page.template == 'blog' or page.template == 'item') %}
             {% include 'partials/archives.html.twig' with {'base_url': new_base_url} %}
         {% endif %}

But I don’t know if it’s correct to filter it like this.
I have tried something like this:

{% if config.plugins.archives.enabled  and archives_show_count|length > 0 %}

But it does not work.

@pmoreno, you can use empty test, or length filter, and check archives_data

{% if config.plugins.archives.enabled and archives_data|length > 0 %}
    {% include 'partials/archives.html.twig' with {'base_url': new_base_url} %}
{% endif %}


{% if config.plugins.archives.enabled and archives_data is not empty %}
    {% include 'partials/archives.html.twig' with {'base_url': new_base_url} %}
{% endif %}

also you must define new_base_url link_1, link_2

Hello @b.da. With this code it works well. My new_base_url was already well defined, I just didn’t know which plugin variable archives to compare against.

Thank you very much again. I will add this new feature in the Future2021 and Editorial themes soon.