studioespresso / craft-date-range

Date range field for Craft CMS
MIT License
12 stars 6 forks source link

Possible to group entries by start date? #18

Closed siebird closed 4 years ago

siebird commented 4 years ago

Trying to group entries by day and I'm not sure if it's possible or just using the wrong syntax. This just outputs the current day. I also tried the .formatted function too

{% set conferenceSchedule = craft.entries.section('schedule').relatedTo(entry).all() %}
{% for day, scheduleByDay in conferenceSchedule|group("eventDate.start|date('l, F jS')") %}
    <div>{{ day }}</div>
    {% for track in scheduleByDay %}
        <div>{{ track.title }} - {{ entry.eventDate.start | date('g:i') }} - {{ entry.eventDate.end | date('g:i a') }}</div>
    {% endfor %}
{% endfor %}
janhenckens commented 4 years ago

Hey @siebird, that seems to be working on my end. I adapted your code a bit to use content from my test section:

{% set conferenceSchedule = craft.entries.section('events').all() %}
{% for day, scheduleByDay in conferenceSchedule|group("eventdate.start|date('l, F jS')") %}
    <div>{{ day }}</div>
    {% for track in scheduleByDay %}
        <div>{{ track.title }} - {{ track.eventdate.start | date('g:i') }} - {{ track.eventdate.end | date('g:i a') }}</div>
    {% endfor %}
{% endfor %}

And that returns:

Wednesday, April 8th
Event 2 - 3:30 - 12:00 pm
Tuesday, March 3rd
Event 1 - 2:30 - 2:30 am

I did change the 5th line to use the eventDate field from the track, not from the entry.

siebird commented 4 years ago

Doh 🤦‍♂️ I was using the wrong date range field. I have a few. Working now