How to add Description as a custom attribute to an autonav - RESOLVED
Permalink 1 user found helpful
I've been struggling with the description handle for quite some time. With a good amount of searching through the forums I was able to come up with the code below in dropdown.php and it worked just fine for a hard coded header navigation.
The problem with this is that I've been unable to create seperate classes for each li without using view.php to add custom attributes to an autonav block. I was able to define the classes as I wanted when I did this but for whatever reason this doesn't want to work with the descriptions.
My site is athttp://www.nomad-sites.com and I know it's not a css problem because I'm using the same stylesheet as before. If anyone could help it'd be greatly appreciated.
The problem with this is that I've been unable to create seperate classes for each li without using view.php to add custom attributes to an autonav block. I was able to define the classes as I wanted when I did this but for whatever reason this doesn't want to work with the descriptions.
My site is athttp://www.nomad-sites.com and I know it's not a css problem because I'm using the same stylesheet as before. If anyone could help it'd be greatly appreciated.
if ($c->getCollectionID() == $_c->getCollectionID()) { echo('<li class="nav-selected nav-path-selected"><a class="nav-selected nav-path-selected" href="' . $pageLink . '">' . $ni->getName() . '<span id="navSelected" class="submenu">' . $_c->getCollectionDescription() . '</span></a>'); } elseif ( in_array($_c->getCollectionID(),$selectedPathCIDs) && $_c->getCollectionID() != 1) { echo('<li class="nav-path-selected"><a class="nav-path-selected" href="' . $pageLink . '">' . $ni->getName() . '</a>'); } else { echo('<li><a href="' . $pageLink . '">' . $ni->getName() . '<span id="navDescription" class="submenu">' . $_c->getCollectionDescription() . '</span></a>'); } $lastLevel = $thisLevel; $i++;
![lackadaize](/files/avatars/147621.jpg)
Or else if anyone could tell me how to assign specific classes to each li of the nav if it's hard coded into the template as in the following code:
Anyone out there? I feel like the following code should work but it's still not displaying the descriptions:
echo '<ul class="nav">'; //opens the top-level menu foreach ($navItems as $ni) { echo '<li class="' . $ni->classes . '">'; //opens a nav item echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $ni->name . '<span id="navDescription" class="submenu">' . $_c->getCollectionDescription() . '</span></a>'; if ($ni->hasSubmenu) { echo '<ul>' ; //opens a dropdown sub-menu } else { echo '</li>'; //closes a nav item echo str_repeat('</ul></li>', $ni->subDepth); //closes dropdown sub-menu(s) and their top-level nav item(s) } } echo '</ul>'; //closes the top-level menu
Since the description may change between versions, you should use the active version of the page object when getting the description.
In the superbly well commented autonav template you may have seen you can reach the page object of the nav item with
Once you have the page object you get instant access to the page version object.
Once you have the active version object, you can get the description for that version with:
So to wrap it all up you can use the below:
I hope this helps.
In the superbly well commented autonav template you may have seen you can reach the page object of the nav item with
$navItem->cObj
Once you have the page object you get instant access to the page version object.
$navItem->cObj->vObj
Once you have the active version object, you can get the description for that version with:
$navItem->cObj->vObj->cvDescription
So to wrap it all up you can use the below:
echo '<ul class="nav">'; //opens the top-level menu foreach ($navItems as $ni) { $description = $ni->cObj->vObj->cvDescription; //set $description to the active page version description echo '<li class="' . $ni->classes . '">'; //opens a nav item echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $ni->name . '<span id="navDescription" class="submenu">' . $description . '</span></a>'; if ($ni->hasSubmenu) { echo '<ul>' ; //opens a dropdown sub-menu } else { echo '</li>'; //closes a nav item echo str_repeat('</ul></li>', $ni->subDepth); //closes dropdown sub-menu(s) and their top-level nav item(s) } } echo '</ul>'; //closes the top-level menu
I hope this helps.
YES!! Thank you so much. Can't tell you how long I've been staring at this problem. I'm just learning php so I've only got a very tiny toothpick paddle. Thanks a million.