2

I have a list of dates which are grouped by year and date and also checks if there is a entry in that year:

{% set allSubmissions = craft.amForms.submissions(
  {
    formHandle: 'reservation',
    limit: null,
    order: 'datum asc',
  })
%} {# Gets all the entries #}

{% set izgrad = now | date('Y-m-d') %} {# format now #}
{% set alteAnmeldung = allSubmissions.dateCreated | date('Y') %}

{% for year, entriesInYear in allSubmissions | group("datum.year") %}

  {% if year >= alteAnmeldung %} {# only show the current and future year #}

    <h3>{{ year }}</h3>
    <ul>
      {% for month, entriesInMonth in entriesInYear | group("datum|date('m')") %}
          {% for day, entriesInDay in entriesInMonth | group("datum|date('d')") %}
            {% for item in entriesInDay %}
              {% if loop.first %}
                {% if izgrad <= item.datum %}
                  <li><a href="#{{ item.datum }}">{{ item.datum | date('d.m.Y') }}</a></li>
                {% endif %}
              {% endif %}
            {% endfor %}
          {% endfor %}
      {% endfor %}
    </ul>

  {% endif %}

{% endfor %}

This works and the list looks like this:

enter image description here

But the code looks horribly inefficient. (this creates 74 db queries). I think there must be a better way to write this. Is it possible to group the fields with less steps for example?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.