Page 1 of 1

[SOLVED] CGCalendar: Display text when no upcoming events

Posted: Thu Jan 27, 2011 5:31 pm
by Hypocrite
I am using the following code to display upcoming events in CGCalendar:

Code: Select all

<div class="cal-upcominglist">

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

	{assign var=month_number value=$event.event_date_start|date_format:"%b"}
	{assign var=end_month_number value=$event.event_date_end|date_format:"%b"}
	{if $event.event_date_start == $event.event_date_end || $event.event_date_end == 0}
	<div class="calendar-date-from"><span class="calendar-date-title">Koulutus alkaa: </span>{$event.event_date_start|date_format:"%e"}. {$event.event_date_start|date_format:"%b"} {$event.event_date_start|date_format:"%Y"}</div>
	{else}
	{if $event.event_date_start|date_format:"%d%m%Y" == $event.event_date_end|date_format:"%d%m%Y"}
	<div class="calendar-date-from"><span class="calendar-date-title">Koulutus alkaa: </span>{$event.event_date_start|date_format:"%e"}.  {$event.event_date_start|date_format:"%b"} {$event.event_date_start|date_format:"%Y"}</div>
	{else}
	<div class="calendar-date-from"><span class="calendar-date-title">Koulutus alkaa: </span>{$event.event_date_start|date_format:"%e"}. {$event.event_date_start|date_format:"%b"} {$event.event_date_start|date_format:"%Y"} {$lang.to} {$event.event_date_end|date_format:"%e"}. {$event.event_date_start|date_format:"%b"} {$event.event_date_end|date_format:"%Y"}</div>
	{/if}
	{/if}
	
	</div>
        <br />
{/foreach}

{if $return_url != ""}
<div class="calendar-returnlink"><a href="javascript:history.go(-1)"> Go back</a></div>
{/if}
</div>
How could I modify this so that it would show a text when there are no upcoming events?

I am using CMS Made Simple 1.9.2 and CGCalendar 1.5.6.

Re: CGCalendar: Display text when there are no upcoming even

Posted: Thu Jan 27, 2011 5:56 pm
by M@rtijn
I guess this will do the trick

Code: Select all

<div class="cal-upcominglist">

{if !isset($event)}no data{/if}

{foreach from=$events key=key item=event}
... rest of your code

Re: CGCalendar: Display text when there are no upcoming even

Posted: Thu Jan 27, 2011 6:11 pm
by Hypocrite
Hmm, doesn't seem to be display correctly.

I have several callbacks in one page for different categories like this:

Code: Select all

<h3>Category 1</h3>

{cms_module module='CGCalendar' display='upcominglist' calendartemplate='raiku' use_session='46451' detailpage='calendar' category='Category 1'}

<h3>Category 2</h3>

{cms_module module='CGCalendar' display='upcominglist' calendartemplate='raiku' use_session='46451' detailpage='calendar' category='Category 2'}

<h3>Category 3</h3>

{cms_module module='CGCalendar' display='upcominglist' calendartemplate='raiku' use_session='46451' detailpage='calendar' category='Category 3'}
When I used your code it showed the text in the first category even though there were upcoming events but didn't display it in the second one where there were no upcoming events.

Re: CGCalendar: Display text when there are no upcoming even

Posted: Thu Jan 27, 2011 8:49 pm
by M@rtijn
Ahh, bit more difficult then I thaught. :-\

I use the {if !isset($event)}no data{/if} for a pastlist, where it works fine. It seems upcominglist behaves different.

The if statement in the template checks if there are events. If not, it shows 'no data'
In pastlist the template is passed with or without events present. Within the template you can use this statement.

It seems upcominglist checks if events exist, if case is 'yes' it passes the template, if the case is 'no' it does nothing. That's why the statement is not working for the categories which are empty.

I've tried to find another solution, but I can't help you out, sorry ::)

Re: CGCalendar: Display text when there are no upcoming even

Posted: Thu Jan 27, 2011 9:45 pm
by psy
This works for me. In the actual page, not the upcoming events template, put:

{capture assign=upcomers}{cms_module module=CGCalendar category=Seminars display=upcominglist}{/capture} {if isset($upcomers) and $upcomers ne null}{$upcomers}{else}
Upcoming Events
There are no events scheduled.
{/if}

hth
psy

Re: CGCalendar: Display text when there are no upcoming even

Posted: Fri Jan 28, 2011 6:56 am
by Hypocrite
Thanks!

That worked like a charm.