Page 1 of 1

CGCalendar List Template: prev/next for month AND year?

Posted: Thu Apr 19, 2018 1:36 pm
by slick
I have a simple CGCalendar list template (shown below) that lets me navigate months of an event calendar. Now I would like to add prev/next navigation for the year as well. Do you have a tip how to do it without resorting to a separate yearlist template? Maybe it's possible with a js-tweak of the standard Ajax list template?

Any hints are much appreciated :)

Code: Select all

<div class="cal-upcominglist">

<div id="springer">
<span class="calendar-prev"><a href="{$nav.prev_url}"><</a></span><span class="calendar-next"><a href="{$nav.next_url}">></a></span>
<span class="calendar-month">{$start_ts|date_format:'%B %y'}</span>
</div>

{foreach from=$events key=key item=event}
<a href="{$event.url}">
<div class="calendar-event">

<div class="four">
<div class="wochentag">{$event.event_date_start|date_format:"%a"}</div>
<div class="monatstag">{$event.event_date_start|date_format:"%e"}</div>
<div class="monat">{$event.event_date_start|date_format:"%b"}</div>
</div>

<h2>{$event.event_title}</h2>
<div class="calendar-summary">{$event.event_summary}</div>

<div class="calendar-info">{$event.fields.Charakter.field_value} – {$event.fields.Ort.field_value} – {$event.event_date_start|date_format:"%H:%M"}</div>

</div>
</a>
{/foreach}

</div>

Re: CGCalendar List Template: prev/next for month AND year?

Posted: Thu Apr 19, 2018 2:48 pm
by velden
This might be useful: https://fullcalendar.io/docs/date-navigation

prevYear and nextYear methods seem available.

Re: CGCalendar List Template: prev/next for month AND year?

Posted: Fri Apr 20, 2018 2:29 pm
by slick
velden wrote:This might be useful: https://fullcalendar.io/docs/date-navigation

prevYear and nextYear methods seem available.
Thanks, I have managed to add the year navigation to the fullcalendar view!

— — —

Here is my attempt to do it in the list view...

$nav.prev_url generates the prev month url in this format:

Code: Select all

index.php?mact=CGCalendar,cntnt01,list,0&cntnt01listtemplate=test2&cntnt01detailpage=detail&cntnt01cal_origparams=YTo4OntpOjA7czo1OiJtb250aCI7aToxO2k6MjAxODtpOjI7aTo0O2k6MztpOjIwO2k6NDtpOjE2O2k6NTtiOjA7aTo2O2k6MTAwMDtpOjc7czowOiIiO30%3D&cntnt01year=2018&cntnt01month=6&cntnt01returnid=44
I modified it like this:

Code: Select all

{assign var=currentmonth value=$start_ts|date_format:'%-m'}
{assign var=prevmonth value=$currentmonth-1}
{assign var=nextmonth value=$currentmonth+1}
{assign var=prevyear value=$year-1}
{assign var=nextyear value=$year+1}

{$nav.prev_url|replace:"year=$year":"year=$prevyear"|replace:"month=$prevmonth":"month=$currentmonth"}
{$nav.next_url|replace:"year=$year":"year=$nextyear"|replace:"month=$nextmonth":"month=$currentmonth"}
This works to navigate the year, but of course it is a nasty smarty hack. Maybe you have a better idea?