Thanks for your quick replies, very useful info here. The intricacy here is that the current (or first upcoming) day
can have more than five events. It should show all events of the first upcoming/current day in any case, even if that means displaying ten events. And if there
are more than four events it should show the first upcoming/currend day’s events only, and only in case there are less than five it should display events of following days to a total amount of five events.
In the meantime I’ve (apparently) solved it with this approach (enhanced with chandra’s suggestion afterwards):
Code: Select all
<table>
<tbody>
{foreach from=$events key=key item=event}
{if $event.event_date_start|strtotime >= $smarty.now}
{if !$stop}
{if $event@iteration === 1}
{assign var="initial_date" value=$event.event_date_start|date_format:'%d'}
{/if}
{if $event.event_date_start|date_format:'%d' !== $startdate}
{assign var="startdate" value=$event.event_date_start|date_format:'%d'}
<tr>
<th colspan="2">{$event.event_date_start|date_format:'%d. %B'}</th>
</tr>
{/if}
<tr>
<td>{$event.event_date_start|date_format:'%H:%M'}</td>
<td>{$event.event_title}</td>
</tr>
{if $event@iteration === 5 && $event.event_date_start|date_format:'%d' !== $initial_date}{$stop = true}{/if}
{/if}
{/if}
{/foreach}
</tbody>
</table>
What it does is it stores the initial day number in a variable on the first iteration and the current iteration’s day in another variable. if the current iteration’s day is different from the previous iteration’s day it prints the day as header row. After five iterations it checks whether the current iteration’s day is still the same as the inital day and if not it stops printing.
How’s that?
I can perhaps even scrap the if statement: {if $event.event_date_start|strtotime >= $smarty.now} since it starts with upcoming events anyway.