I would like to show a list of all existing categories (and get their assigned colors in the admin area) on the list template (or any calendar template). As far as I can tell there is only an “events” array where each event reveals the assigned category. I suppose I could loop through all events, retreive their categories, and construct a list with a few conditionals (remember, I only want each category once in that list, so subsequent similar occurrences should be ignored) but that feels a little too intricate.
I know that the editevent template has a “categories” variable/array. Couldn’t that also be made available in the calendar templates? And while I’m at it: Could that “categories” array not contain the color values that are assigned to them in admin?
[CGCalendar] get category names (and colors) in list templat
Re: [CGCalendar] get category names (and colors) in list tem
Here's a way of doing something similar which should help you.
It generates a key, showing each category within a coloured div. CMSMS V1.
Create a UDT, "get_cgcalendar_categories":
And in calendar template I have:
My CSS includes styles with the same name as each category; not quite what you want but you should be able to get there now? You should find the colours within the returned array. Perhaps something like {$cgc_cat.category_colour}
It generates a key, showing each category within a coloured div. CMSMS V1.
Create a UDT, "get_cgcalendar_categories":
Code: Select all
/**
* Get list of CGCalendar categories and assign to Smarty variable.
*
* @params string $params['assign'] Mandatory. Name of variable to assign result
*/
$assign = trim($params['assign']);
if (!empty($assign)){
$gCms = cmsms(); // global $gCms;
$db = $gCms->GetDB(); // cms_utils :: get_db();
$smarty = $gCms->GetSmarty(); // cms_utils :: get_smarty();
$dbresult = FALSE;
$query = 'SELECT * FROM `'.cms_db_prefix().'module_cgcalendar_categories` ORDER BY `category_order`, `category_name`, `category_id`';
$dbresult = $db->GetArray($query);
if(!empty($dbresult)){
$smarty->assign($assign, $dbresult);
}
}
Code: Select all
<div class="cal-cat-key">
{* udt call *}
{get_cgcalendar_categories assign='cgc_cats'}
{if !empty($cgc_cats)}
<h3>Key</h3>
{foreach from=$cgc_cats item='cgc_cat'}
<div class="{$cgc_cat.category_name}">{$cgc_cat.category_name}</div>
{/foreach}
{/if}
</div>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] get category names (and colors) in list tem
Thanks. That looks kinda “hacky”, though, directly accessing the database without any API. And even though I’m still using version 1 of the CMS I’m determined to upgrade to version 2 as soon as possible so I’d prefer to have a solution that works there, too.
If nobody else comes up with anything (calguy1000 *wink wink*) I’m going to file a feature request.
If nobody else comes up with anything (calguy1000 *wink wink*) I’m going to file a feature request.


