Unique class or id for list items in autonav

Permalink
Hi,

Maybe someone can shed some light on how to do this or suggest a better way than trying to mod the autonav.

I need to highlight specific menu items in different colours (i.e. the links home, about and contact will have different css properties), but realise there are no classes on list items within an autonav list other than 'nav-path-selected' and 'nav-selected'.

Is there a way of modding the autonav or using CSS in a way I haven't thought of to do this?

Thanks,

osu

osu
 
Mnkras replied on at Permalink Reply
Mnkras
Custom template with a foreach argument?
osu replied on at Permalink Reply
osu
How do I get the individual ID of the page being linked to? My code so far is below (I've added 'Begin' and 'End' comments around the changes I made).

All I did was use the header_menu.php block template [copied it to /blocks/autonav/templates] and then used the cID for the unique ID and prepended 'nav-' as CSS classes can't start with a number.

Thanks

osu

<?php 
   defined('C5_EXECUTE') or die(_("Access Denied."));
   $aBlocks = $controller->generateNav();
   $c = Page::getCurrentPage();
   echo("<ul class=\"nav-header\">");
   $nh = Loader::helper('navigation');
   $isFirst = true;
   foreach($aBlocks as $ni) {
      $_c = $ni->getCollectionObject();
      if (!$_c->getCollectionAttributeValue('exclude_nav')) {
         if ($ni->isActive($c) || strpos($c->getCollectionPath(), $_c->getCollectionPath()) === 0) {
            $navSelected='nav-selected';
         } else {
            $navSelected = '';
         }
osu replied on at Permalink Reply
osu
Might it be something to do with $ni?

Can't find anything about $ni in the documentation though...

EDIT

This is a solution, but I'd still be interested to know how one could do it with the ID of the link in question.

Hope it helps someone:

<?php 
   defined('C5_EXECUTE') or die(_("Access Denied."));
   $aBlocks = $controller->generateNav();
   $c = Page::getCurrentPage();
   echo("<ul class=\"nav-header\">");
   $nh = Loader::helper('navigation');
   $isFirst = true;
   foreach($aBlocks as $ni) {
      $_c = $ni->getCollectionObject();
      if (!$_c->getCollectionAttributeValue('exclude_nav')) {
         if ($ni->isActive($c) || strpos($c->getCollectionPath(), $_c->getCollectionPath()) === 0) {
            $navSelected='nav-selected';
         } else {
            $navSelected = '';
         }
faxe replied on at Permalink Reply
faxe
Hi,
I was solving the same problem.. and finally I did it like this:
(editing the same file as you, in version 5.5.2.)

foreach($aBlocks as $key => $ni) { //line 10 in my file
//(...)
         if ($isFirst) $isFirstClass = 'first';
         else $isFirstClass = '';
         echo '<li class="menuitem'.$key.' '.$navSelected.' '.$isFirstClass.'">'; //line 41 in my file
//(...)


btw. I think that $ni does not have any special meaning... maybe an abbreviation of Navigation Item (?)