CGCalendar - Color of Categories

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
slabbe
Forum Members
Forum Members
Posts: 29
Joined: Wed Sep 28, 2011 1:22 am

CGCalendar - Color of Categories

Post 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?
applejack
Power Poster
Power Poster
Posts: 1014
Joined: Fri Mar 30, 2007 2:28 am

Re: CGCalendar - Color of Categories

Post 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/
staartmees
Power Poster
Power Poster
Posts: 1049
Joined: Wed Mar 19, 2008 4:54 pm

Re: CGCalendar - Color of Categories

Post by staartmees »

How can I retrieve the category of each event in the calendartemplate of CGCalendar?
applejack
Power Poster
Power Poster
Posts: 1014
Joined: Fri Mar 30, 2007 2:28 am

Re: CGCalendar - Color of Categories

Post 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.
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: CGCalendar - Color of Categories

Post 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?
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation

CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
staartmees
Power Poster
Power Poster
Posts: 1049
Joined: Wed Mar 19, 2008 4:54 pm

Re: CGCalendar - Color of Categories

Post 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
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Contact:

Re: CGCalendar - Color of Categories

Post 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.
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation

CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
JohnnyB
Dev Team Member
Dev Team Member
Posts: 731
Joined: Tue Nov 21, 2006 5:05 pm

Re: CGCalendar - Color of Categories

Post 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}
"The art of life lies in a constant readjustment to our surroundings." -Okakura Kakuzo

--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
applejack
Power Poster
Power Poster
Posts: 1014
Joined: Fri Mar 30, 2007 2:28 am

Re: CGCalendar - Color of Categories

Post 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}
Post Reply

Return to “Modules/Add-Ons”