All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Grouping events by day, in the next week

Jon 20 May 2013 09:31 question, complete

Hey Low

I need to display a list of events in Low Events that are coming up in the next week, showing a single heading and container div for each day. Some days have no events, others have 1, and occasionally, a day will have more than 1 event.

It's kind of like a calendar grid view, but slightly simpler, and events shouldn't be shown on 2 days if they run past midnight.

For example:

*Monday*
Event 1

*Tuesday*
Event 2
Event 3

*Wednesday*
Event 4

*Friday*
Event 5

*Saturday*
Event 6

*Sunday*
Event 7
Event 8
Event 9

This tag works perfectly, assuming there's not more than 1 event per day:


{exp:low_events:entries channel="events" date="now;+6 days" show_passed="no"}
<div class="panel">
<h4>{nightlyevent_time:start_date format='%l %j%S'}</h4>
{title}
</div>
{/exp:low_events:entries}


When there are multiple events on a single day, you get the following for Tuesday, of course, with duplicated


<div class="panel">
Tuesday 21st
Event 2 details here
</div>

<div class="panel">
Tuesday 21st
Event 3 details here
</div>


So, I tried the quick fix, with 7x exp:low_events:entries, one per day. This would be great, but now, when there's an event which runs after 12 midnight, it will appear inside 2x days, which isn't desirable.

Here's that code:

{exp:low_events:entries channel="events" unit="custom" date_from="+1 day" date_to="+1 day" show_passed="no"}


The only solution that comes to mind right away for our scenario is a parameter to ignore the event end-date. So for a exp:low_events:entries loop, require that the start date of the event falls within the current entries loop. Otherwise, don't show it?

I guess some kind of crazy Stash method might be a solution too. Is there anything you can recommend?

Replies

  1. Low 20 May 2013 09:43

    You can try an use the first:-variable for only targeting the first event of a given unit (day, in your case). That should give you an option to show the header for only the first event of the day.

    http://gotolow.com/addons/low-events/...

    There isn't a last:-variable at the moment, so creating the wrapping div (and especially the closing tag) may prove difficult. But perhaps you could work your way around that.

  2. Jon 20 May 2013 11:26

    Thanks for such a quick response!

    I think unfortunately the layout is too complex to be able to get away with just a check for 'first event of the day', though that's a handy tag!

    I'm starting to think that I'll have to opt for the 7x exp:low_events:entries tags in order to give the flexibility to adjust the layout a bit more if there's more than 1 event per day, but the only way to do that would be to have some method to query the start time of the event, either a started_in_period type parameter (ideal), or a way to do the following:


    {exp:low_events:entries channel="events" unit="custom" date_from="+3 days" date_to="+3 days" show_passed="no"}

    {if nightlyevent_time:start_date > date_from}

    {!-- Show the event details, with wrapper HTML etc --}
    {nightlyevent_time:start_date format='%l %j%S'}
    {title}

    {else}

    {!-- Don't show this event because it would have been shown on a previous day --}

    {if}

    {/exp:low_events:entries}


    Really appreciate the help so far - I don't suppose you have any ideas for any other ways to achieve that?

  3. Low 20 May 2013 11:45

    I think having a single low_events:entries tag is better. There should be a way of grouping the events per day with some clever templating. Something like this should work:

    {exp:low_events:entries} 
    {if '{events_field:first unit="day"}' == 'y'}
    {if count != 1}</div>{/if}
    <div class="panel">
    Event header here
    {/if}
    event details here
    {if count == total_results}</div>{/if}
    {/exp:low_events:entries}