Page 1 of 1

CGCalendar - Color of Categories

Posted: Wed Aug 13, 2014 6:23 pm
by slabbe
With the new version of CGCalendar, we can now add colors to categories and I haven't seen any mention that we can use it on the Front-end. Is there anyway to get this information on the front end and use it in the tpl of cgcalendar?

Re: CGCalendar - Color of Categories

Posted: Thu Aug 14, 2014 1:58 am
by applejack
You have been able to do this for a long time. Just use the categories as the class for each date.

http://www.seafin.co.uk/availability/

Re: CGCalendar - Color of Categories

Posted: Thu Aug 14, 2014 7:23 am
by staartmees
How can I retrieve the category of each event in the calendartemplate of CGCalendar?

Re: CGCalendar - Color of Categories

Posted: Thu Aug 14, 2014 11:43 am
by applejack

Code: Select all

{foreach from=$day.events item=event}
{foreach from=$event.categories item=class}
class={$class.category_name|lower}"
{/foreach}
{/foreach}
This is on an old install of CMS so it may have changed.

Re: CGCalendar - Color of Categories

Posted: Mon Dec 08, 2014 4:24 am
by paulbaker
applejack wrote:it may have changed.
It looks like it has changed. On a CMSMS 1.11.10 running CGCalendar 1.13.4 (not quite latest), "category_name" now appears to be numbers. :'(

No doubt this is due to the extensive updates this module has received recently.

Any ideas on how to get category names back, anyone?

Re: CGCalendar - Color of Categories

Posted: Mon Dec 08, 2014 5:14 am
by staartmees
You could do it with an IF-statement.
The problem I'm facing: if the category_name is e.g. 12 or 18, I get for both 1

Re: CGCalendar - Color of Categories

Posted: Mon Dec 08, 2014 2:44 pm
by paulbaker
staartmees wrote:You could do it with an IF-statement.
The problem I'm facing: if the category_name is e.g. 12 or 18, I get for both 1
Good idea staartmees. My "category_name"s come out as single figures (2, 5 etc) so I am able to "solve" (hack really) like this, which changes the link class according to category:

Code: Select all

{foreach from=$day.events item=event}
{foreach from=$event.categories key=category item=item}

<li><a class="{if $item.category_name == "2"}Club{elseif $item.category_name == "5"}Training{elseif $item.category_name == "4"}Social{elseif $item.category_name == "3"}Non{/if}" href="{$event.url}">{$event.event_title}</a></li>

{/foreach}
{/foreach}
Of course this is far from ideal because when a new category is added in CGCalendar I will have to remember* to change this template.

* I won't remember.

Re: CGCalendar - Color of Categories

Posted: Mon Dec 08, 2014 4:26 pm
by JohnnyB
Here's another similar way to work with the category name instead of ID in the loop.
- note that the $event.categories loop has to be nested in a $events loop just like paulbaker's example:

Code: Select all

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

	{foreach from=$event.categories key='key' item='categoryid'}
		{if $key == 'your-cateogry-name-1'}Do Something
		{elseif $key == 'your-cateogry-name-2'}Do Something Else
		{elseif $key == 'your-cateogry-name-3'}Do Something Else
		{else}Some Default that doesn't fit anywhere else
		{/if}
	{/foreach}
	
{/foreach}

Re: CGCalendar - Color of Categories

Posted: Mon Dec 08, 2014 4:44 pm
by applejack
or

Code: Select all

{foreach from=$day.events item=event}
{foreach from=$event.categories key=category item=item}
<li><a class="calendar-class{$item.category_name}" href="{$event.url}">{$event.event_title}</a></li>
{/foreach}
{/foreach}