I am grouping entries that have the same date together so that I only get a single date. Works great.

I would like to loop through each entry that has that date and I'm not having much luck. I want to show

Here is what I have so far:

{% for date, attempt in attempts|group('attemptDate') %}
        <td>{{ date|date('M j, Y') }}</td>
        {% if type == 'My Type' %}
            {# Get all entries where type = My Type & entry.attemptDate = date. #}
            {% set total = 0 %}
            {% count = 0 %}
            {% for ?? in ?? %} {# 
                {% total = loop.index %}
                {% count = {# if value in myField is true #} %}
                <td>{{ count }}/{{ total }}</td>
            {% endfor %}
        {% endif %}
{% endfor %}

Thank you for any suggestions!

  • 1
    {% for entry in attempt not working? %}
    – Jan_dh
    Jan 29 '17 at 9:31

This should work:

{% for date, attempt in attempts|group('attemptDate') %}
      <td>{{ date|date('M j, Y') }}</td>
      {% for entry in attempt %}
        {% if entry.type == 'My Type' %}
          <td>{{ entry.title }}</td>
        {% endif %}
      {% endfor %}
  {% endfor %}

I don't know what you want to do with the 'type' of the entries? But if you want to limit the amount of entries according to type, you could fill "attempts" with all entries of a certain type first and then loop through them. Than you could remove the if statement which would be cleaner and faster I think.

So something like:

{% set attempts = craft.entries.section("something").type("My Type").find() %}

If I understand correctly, you want to show a list of entries that only match the entry type of "My Type" and group them together by date. A simplified list might look something like this:

Jan 1, 2017
  entry 1
  entry 5
  entry 8

Jan 4, 2017
  entry 2
  entry 4
  entry 11

Jan 11, 2017
  entry 6

First, you'll have to specify the entry type with it's handle (camel case) like "myType" not "My Type."

Following the example from Craft's docs on the group filter, you would probably do something like this:

{# Get attempts entries matching entry type 'myType' #}
{% set attempts = craft.entries.section('attempts').type('myType').find() %}

{# Group attempts by date #}
{% for date, attemptsByDate in attempts|group('attemptDate.day') %}

  <h2>{{ date|date('M j, Y') }}</h2>

  {# loop thru the attempts grouped by date  #}
    {% for entry in attemptsByDate %}
      <li>{{ entry.title }}</li>
    {% endfor %}
{% endfor %}

If there were other entries that didn't match type 'myType' on another day, say Jan 3rd, you won't see Jan 3rd in the list at all.

I'm not totally sure what you need to do with {{ count }} and {{ total }}, but hopefully this gets you on the right track.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.