Skip to content

Date on "Archives" page bug #343

@so1der

Description

@so1der

Hello there! So I came across a bug - even when the articles have the same date, "archive" template will create an separate <dt> block for each of them anyway. For example:

01.01.2025
Article 1
01.01.2025
Article 2

When it should be as follows:

01.01.2025
Article 1
Article 2

As far as I can tell, the problem is in this line of code:

 {% set previous_date = article.locale_date %}

set wont pass the variable value across the "for" loop. For that purpose the "namespace" should be used:

{% extends "base.html" %}

{% block title %} &ndash; {{ _('Archives') }}{% endblock %}

{% block content %}
<article class="single">
  <header>
    <h1 id="archives">{{ _('Archives') }}</h1>
  </header>
  <div>
    <dl>
      {% set ns = namespace(previous_date=False) %} 

      {% for article in dates %}
        {% if article.locale_date != ns.previous_date %}
          {% set ns.previous_date = article.locale_date %}
          <dt>{{ article.locale_date }}</dt>
        {% endif %}

        <dd>
          <a href="{{ SITEURL }}/{{ article.url }}">{{ article.title }}</a>
        </dd>
      {% endfor %}
    </dl>
  </div>
</article>
{% endblock %}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions