Page 1 of 1

[CGCalendar] Group events by month

Posted: Sat May 28, 2011 3:51 pm
by vinyl
For a site I would like to make a calendar on the frontpage which lists upcoming events.

My idea idea is to do it in this way:

MONTH
-DATE
-TITLE
------------
-DATE
-TITLE
------------
MONTH
-DATE
-TITLE

Is it possible to group calendar events by month? Maybe by keeping a variable for the current month and if the month variable differs from the kept variable add a month title?

Re: [CGCalendar] Group events by month

Posted: Mon May 30, 2011 7:10 am
by vinyl
Found a solution for this. Will post my code for someone else to use.

Code: Select all

{assign var=month_check value=""}

{foreach from=$events key=key item=event}

{assign var=month_number value=$event.event_date_start|date_format:"%m"}
{assign var=end_month_number value=$event.event_date_end|date_format:"%m"}

{if $month_check == ""}
{assign var=month_check value=$month_number}
<h2>{$event.event_date_start|date_format:"%B"}</h2>

{elseif $month_check != $month_number}
<h2>{$event.event_date_start|date_format:"%B"}</h2>
{assign var=month_check value=$month_number}
{/if}

rest of the calendar markup

{/foreach}