Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

dynamic cms sitetree icon


15 Posts   2971 Views

James Bolitho

20 December 2011 at 8:45am Community Member, 33 Posts


I have found myself in the same situation Keeny is describing. I know this is an oldish post and I have looked around but I haven't been able to work out a way to solve this yet. Has anyone achieved this? Would you be kind enough to share or point in the right direction.




20 December 2011 at 11:18pm Community Member, 9 Posts


i have found a solution.
You can add the __construct function to the Page Class.

function __construct($record = null, $isSingleton = false) {
parent::__construct($record, $isSingleton);
if((bool)$record['YOURSETTING']) Object::set_static('Page', 'icon', 'PATH/TO/TREEICONS/ICON');

That´s it.

James Bolitho

21 December 2011 at 1:57am Community Member, 33 Posts

Hi Pelse,

Thanks for this but I cannot seem to get this to work. I am probably missing something obvious. Here is my code:

class SimpleShopCategoryPage extends Page
public static $db = array(
      'CategoryPageCopy' => "Boolean"
function __construct($record = null, $isSingleton = false) {
      parent::__construct($record, $isSingleton);
      if((bool)$record['CategoryPageCopy']) Object::set_static('SimpleShopCategoryPage', 'icon', 'SimpleShop/images/treeicons/storecopy');

What am I doing wrong? Thanks for your help.



James Bolitho

24 December 2011 at 6:14am Community Member, 33 Posts


I have had another look at this and the reason it is not working is because the if clause is returning false.

I did the following:

echo $record['CategoryPageCopy'];

and it returned the following value: 11111111

Can anyone explain why this is doing this as I thought it would return 1 or 0 depending on whether the checkbox was ticked? I am now a little confused.




9 January 2012 at 7:11pm Forum Moderator, 5511 Posts

Can anyone explain why this is doing this as I thought it would return 1 or 0 depending on whether the checkbox was ticked? I am now a little confused.

I would hazard a guess that your constructor is being called multiple times, hence the multiple 1's. If you echo "1." you'll likely see

James Bolitho

7 March 2012 at 5:24am Community Member, 33 Posts


Thanks Willr for the response. I have created a round about solution for this and I thought I would share how I did it. It doesn't replace the page icon but adds a new class to the list items on a site tree if a checkbox on this particular page class is ticked allowing you to add styling to make it stand out on the site tree.

Here is the code:

1) Add to config file details of custom extension, js and css to be included on CMS Main page.


//Change icon background if copy category
//custom extension
LeftAndMain::add_extension('LeftAndMain', 'ActsLeftAndMain');

2) Custom extension to do a database query and return all page id's where the checkbox has been checked.


class ActsLeftAndMain extends Extension {
   function getData(){
      $records = DB::query ("SELECT `CategoryPage`.`ID` FROM `CategoryPage` WHERE `CategoryPage`.`CategoryPageCopy` = 1");
      if($records) {
         $i = 0;
         $length = count($records)-1;
         foreach($records as $singlerecord){
            if($i == $length) {
               $set = $singlerecord['ID'];
            } else {
               $set .= ",";
               $set .= $singlerecord['ID'];   
         return $set;

3) Create a modified template to output data.


<div id="CategoryPageCopyIDs" style="height: 0px; display: none;">$getData</div>
<div id="form_actions_right" class="ajaxActions">

<% if EditForm %>
<% else %>
   <form id="Form_EditForm" action="admin?executeForm=EditForm" method="post" enctype="multipart/form-data">

      <p><% _t('WELCOMETO','Welcome to') %> $ApplicationName! <% _t('CHOOSEPAGE','Please choose a page from the left.') %></p>
<% end_if %>

<p id="statusMessage" style="visibility:hidden"></p>

4) Add some jQuery to grab info from page and add new or remove css class to the sitetree nodes.


(function(jQuery) {
jQuery(document).ready(function() {
   //Gets the ID's of category pages
   var IDs = jQuery('div#CategoryPageCopyIDs').html();
      var IDsString = jQuery.parseJSON('[' + IDs + ']');         
      jQuery.each(IDsString, function() {
         jQuery('li#record-'+ this).addClass('copyIcon');
   jQuery("input#Form_EditForm_action_publish").live("click", function() {            
      var ID = jQuery('input#Form_EditForm_ID').val();
      if(jQuery('#Form_EditForm input#Form_EditForm_CategoryPageCopy').is(':checked')) {
         jQuery('li#record-'+ ID).addClass('copyIcon');   
      } else {
         jQuery('li#record-'+ ID).removeClass('copyIcon');

5) Add styling to the sitetree nodes.


ul.tree li.copyIcon {
background: #E8F3FC;
border-radius: 10px;
/* CSS3 tweaks for modern browsers */

That will allow you to easily tell if you have a checkbox ticked on a certain page and updates when save and publish is pressed or the window is reloaded. I hope this helps others.




22 June 2012 at 8:36pm Community Member, 1 Post

I found another (simpler) solution to this one, in the page class you want his just override CMSTreeClasses function to add the classes you like and modify it with css

function CMSTreeClasses($controller) {
      $classes = parent::CMSTreeClasses($controller);
      if($this->Status == "Published")
         $classes .= " yourCustomCssClass";
      return $classes;