CGCalendar - Color of Categories
CGCalendar - Color of Categories
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
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/
http://www.seafin.co.uk/availability/
-
- Power Poster
- Posts: 1049
- Joined: Wed Mar 19, 2008 4:54 pm
Re: CGCalendar - Color of Categories
How can I retrieve the category of each event in the calendartemplate of CGCalendar?
Re: CGCalendar - Color of Categories
Code: Select all
{foreach from=$day.events item=event}
{foreach from=$event.categories item=class}
class={$class.category_name|lower}"
{/foreach}
{/foreach}
Re: CGCalendar - Color of Categories
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.applejack wrote:it may have changed.

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
https://docs.cmsmadesimple.org/troubles ... nformation
CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
-
- Power Poster
- Posts: 1049
- Joined: Wed Mar 19, 2008 4:54 pm
Re: CGCalendar - Color of Categories
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
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
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: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
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}
* 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
https://docs.cmsmadesimple.org/troubles ... nformation
CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
Re: CGCalendar - Color of Categories
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:
- 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.
--
--
LinkedIn profile
--
I only speak/write in English so I may not translate well on International posts.
--
Re: CGCalendar - Color of Categories
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}