Multiple calendars with dynamic month/year calculation

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
RonnyK
Support Guru
Support Guru
Posts: 4962
Joined: Wed Oct 25, 2006 8:29 pm
Location: Raalte, the Netherlands

Multiple calendars with dynamic month/year calculation

Post by RonnyK »

I needed 3 calendars on a page, but couldnt find a script that did this. There where logics with fixed months/years, but nothing dynamically, so I ended up with writing the following logic.....

I created a GCB, where I inserted this logic, the GCB is then called in the template, where the calendars should appear.

Code: Select all

{assign var=maand value=$smarty.now|date_format:"%m"} 
{assign var=jaar value=$smarty.now|date_format:"%Y"} 

{cms_module module="Calendar" month=$maand year=$jaar} 
{if $maand gt 11} 
{assign var=maand1 value=$maand+1-12} 
{assign var=jaar1 value=$jaar+1} 
{cms_module module="Calendar" month=$maand1 year=$jaar1} 
{else} 
{assign var=maand2 value=$maand+1} 
{cms_module module="Calendar" month=$maand2 year=$jaar} 
{/if} 
{if $maand gt 10} 
{assign var=maand3 value=$maand+2-12} 
{assign var=jaar3 value=$jaar+1} 
{cms_module module="Calendar" month=$maand3 year=$jaar3} 
{else} 
{assign var=maand4 value=$maand+2} 
{cms_module module="Calendar" month=$maand4 year=$jaar} 
{/if} 
Ronny
Peciura

Re: Multiple calendars with dynamic month/year calculation

Post by Peciura »

And this is template for multiple instances of  CGCalendar. I have modified RonnyK's template dropped to pastebin.
You will have to set number of columns and number of months you want to show.
{assign var='col_num' value='2'}{*number of columns*}
{assign var='month_num' value='5'}{*number of months to be displayed*}

{assign var='current_month' value=$smarty.now|date_format:"%m"}
{assign var='current_year' value=$smarty.now|date_format:"%Y"}



{section name='months' start=$current_month loop="`$current_month+$month_num`"}
{assign var='month' value="`$smarty.section.months.index%12`"}
{if $month==0}
{assign var='month' value='12'}
{/if}
{if 1=="`$smarty.section.months.iteration%$col_num`"}

{/if}
{assign var='year' value="`$current_year+$smarty.section.months.index/12`"|intval}

{cms_module module="CGCalendar" year=$year month=$month first_day_of_week='0'}{*  CGCalendar call *}

{if 0==$smarty.section.months.iteration%$col_num}

{/if}
{/section}

Attachments
multiple_cgcalendar.gif
Last edited by Peciura on Sat Apr 10, 2010 7:52 pm, edited 1 time in total.
cyberman

Re: Multiple calendars with dynamic month/year calculation

Post by cyberman »

Great thing - thx!

Got some support requests in the past for things like this.
Peciura

Re: Multiple calendars with dynamic month/year calculation

Post by Peciura »

One will have more fun if months can be switched inline and independently http://forum.cmsmadesimple.org/index.ph ... #msg206300
Last edited by Peciura on Fri Apr 30, 2010 5:13 pm, edited 1 time in total.
User avatar
DaRichMan
Forum Members
Forum Members
Posts: 64
Joined: Mon Oct 20, 2008 11:31 am
Location: Netherlands

Re: Multiple calendars with dynamic month/year calculation

Post by DaRichMan »

@ Peciura (and any other who knows);

Thanx to your example I ended up with almost the look I want. One little thing, if there is an event in the calendar it shows the name of it in the calendar (see sreenshot).
Is it possible to make the days which contain an event clickable and not show the title of the event?
Attachments
calender.jpg
RonnyK
Support Guru
Support Guru
Posts: 4962
Joined: Wed Oct 25, 2006 8:29 pm
Location: Raalte, the Netherlands

Re: Multiple calendars with dynamic month/year calculation

Post by RonnyK »

Sure,

remove the call in the a-href that shows the {$event.event_details}. Just remove that part, make sure that the day-remains clickable.

Ronny
Post Reply

Return to “Tips and Tricks”