reading value of select attribute

Permalink
Hi,
I am trying to have customized menu, based on attributes. In one of the tutorials I read how to do that.

I have the attribute top_menu_class added to some of my pages, I created customized template in autonav/templates and it is working fine.

Now I am trying to customize the menu adding some icons via css. Each menu needs its own icon, so I wanted to add the class to the html via attribute in C5. I decided that the best way would be having list of predefined attributes. I created select attribute with options like
home, faq, help and blog.

Now in the customized file
header_menu_top.php (based on original header_menu) I would like to read the value of selected attribute, but it seems that value is private and I can't find correct method to read it.

I would appreciate if I could get some help.



Piece of code:


foreach($aBlocks as $ni) {
$_c = $ni->getCollectionObject();
if ($_c->getCollectionAttributeValue('top_menu_class')) {
...

//I don;t know how to read value stored in
$_c->getCollectionAttributeValue('top_menu_class')->options[0]['value']

I can see that the value of the attribute sits there but can't access that variable.


I will appreciate any help

Thanks

Norbert

 
tronix replied on at Permalink Reply
I will answer myself.
I tried to access this private properties finding them by print_r, but actually it was very easy.

The code below creates custom menu from pages that uses select attribute which name is 'top_menu_class'. Additionally it adds css class that is defined by this attribute.

Thanks to that construction I can simply build graphical top menu:

Here's my header_menu_top.php file

defined('C5_EXECUTE') or die("Access Denied.");
   $aBlocks = $controller->generateNav();
   $c = Page::getCurrentPage();
   echo("<ul class=\"nav-header-top\">");
   $nh = Loader::helper('navigation');
   $isFirst = true;
   foreach($aBlocks as $ni) {
      $_c = $ni->getCollectionObject();
// get the attribute value and assign it to
// $iconclass variable 
$iconclass=$_c->getCollectionAttributeValue('top_menu_class');
      if ($iconclass) {
         $target = $ni->getTarget();
         if ($target != '') {
            $target = 'target="' . $target . '"';


Brgs
Norbert