Page 1 of 1

If no events to list, show a default message

Posted: Mon Sep 01, 2008 7:45 pm
by marisafal
Hi, I'm trying to set my upcoming events list to show a default message if there are no events to list.  I tried to make a modified version of Elijah Lofgren's count_news_items user defined tag, but I pretty much botched it up. Has anyone had success doing this?  Any help is greatly appreciated. Thanks!

Using CMSMS 1.4 Jamaica
Calendar 0.8.2

Re: If no events to list, show a default message

Posted: Wed Oct 01, 2008 6:28 pm
by cnisvcs
I was looking for this too and couldn't find the answer on the forum, so I did some digging in the code. It turns out that probably the easiest solution is using smarty {foreachelse} clause. In your CMS admin area go to Calendar and switch to the template tab you are working with (list or upcoming). In the code find {/foreach} then add {foreachelse} with your message code right berfore it. Your template should have the structure as follows:



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

    ... bunch event listing code ...

{foreachelse}

    no events ...or the other message of your choice

{/foreach}



According to smarty website: {foreachelse} is executed when there are no values in the from variable.

Best regards

Re: If no events to list, show a default message

Posted: Wed Oct 01, 2008 9:44 pm
by marisafal
You rock! Thanks so much for your reply! I'm going to try it out now!

[SOLVED] If no events to list, show a default message

Posted: Wed Oct 01, 2008 10:07 pm
by marisafal
Hurrah! It worked! Thanks so much!  I knew I needed a snippet of code, but I just kept getting it wrong.  You might consider posting this to the Tips & Tricks section?