1

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') %}
    <tr>
        <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 %}
    </tr>
{% endfor %}

Thank you for any suggestions!

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

This should work:

{% for date, attempt in attempts|group('attemptDate') %}
    <tr>
      <td>{{ date|date('M j, Y') }}</td>
      {% for entry in attempt %}
        {% if entry.type == 'My Type' %}
          <td>{{ entry.title }}</td>
        {% endif %}
      {% endfor %}
    </tr>
  {% 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() %}
| improve this answer | |
1

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  #}
  <ul>
    {% for entry in attemptsByDate %}
      <li>{{ entry.title }}</li>
    {% endfor %}
  </ul>
{% 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.

| improve this answer | |

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.