Add the text "no posts found" in archives

Hi all. I’d like to add the text “no posts found” in my multiple blogs when no posts are present on a certain month.
I use the standard “Archives” plugin by TeamGrav.
I think i have to write a {% if %} condition in the following code:

<ul class="archives">
{% for month,items in archives_data %}
 <a href="{{ page.url }}/{{ config.plugins.archives.taxonomy_names.month }}{{ config.system.param_sep }}{{ month|date('M_Y')|lower|e('url') }}">
{% if archives_show_count %}
<span class="label">{{ items|length }}</span>
{% endif %}
 <span class="archive_date">{{ month|date(config.plugins.archives.date_display_format) }} </span>
{% endfor %}

My problem is I’m no coder, so I need same help in writing the correct {% if %} condition for missing posts and pasting it in the above code, something like

{% if items = 0 %}
<p>No posts found for this month.</p>
{% endif %}

Thanks in advance!

Anyone can help?? i couldn’t find a reply to my problem here or in gravdiscord chat…

@maria, Having taken a look at the Archives plugin, I get the impression that the array ‘archives_data’ only contains year/month combinations for which at least 1 item exist.

That means that {% if (items|length) == 0 %} never happens…

You are using an assignment instead of a conditional statement. Small typo, big effect :slight_smile:

Simply change

{% if items = 0 %}


{% if items == 0 %}

@bleutzinn, ‘items’ is an array, so the correct syntax should be:

{% if (items | length) == 0 %}
{% endif %}

The syntax {% if items = 0 %} would have thrown an error:

0 - Unexpected token “operator” of value “=” (“end of statement block” expected).

Thank you so much for correcting my “If” code. Now a further question: how can I alter the default archives.htm.twig file to add the “if” condition? Coming from Joomla (completely different environment!!) my learning curve especially about twig s painfully slow … :wink:

@pamtbaau, thanks for your correction.

Editing Twig template files is done outside of Grav by using a text or code editor of your choosing.