Auto-Nav Template with Unique CSS Classes
Permalink 4 users found helpfulHere is a working model to use if anyone is interested. Just place this in your blocks/autonav/templates directory. I named mine custom_nav.php
All I did was call the $_c->getCollectionID() method to add it to each navigation item and I moved the nav-selected class into an ID. Otherwise, this is exactly the same as the existing auto-nav.
Enjoy!
<?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')) { $target = $ni->getTarget(); if ($target != '') { $target = 'target="' . $target . '"'; } if ($ni->isActive($c) || strpos($c->getCollectionPath(), $_c->getCollectionPath()) === 0) {
(Great suggestion by the way, nice and clean and easily extendable)
This will now add the following classes:
nav-selected - no change
nav-path-selected - no change
nav-first - Applied to the first li in the list, marginal uses
nav-item-{cid}
It'll now also check for a new attribute if you have it defined, 'nav_item_class', so if you wanted to give your your class a name better than nav-item-94, you can do nav-item-contact-popup or whatever.
<? defined('C5_EXECUTE') or die("Access Denied."); $aBlocks = $controller->generateNav(); $c = Page::getCurrentPage(); $containsPages = false; $firstNavLi = true; $nh = Loader::helper('navigation'); //this will create an array of parent cIDs $inspectC=$c; $selectedPathCIDs=array( $inspectC->getCollectionID() ); $parentCIDnotZero=true; while($parentCIDnotZero){ $cParentID=$inspectC->cParentID; if(!intval($cParentID)){ $parentCIDnotZero=false;
Perhaps for backwards compatibility, we could create:
$aBlocks = $controller->generateNavHierarchy();
I like your approach better...seems to make the most sense.
Warning: in_array() [function.in-array]: Wrong datatype for second argument in /blocks/autonav/templates/custom_menu_compatible.php on line 48
If that's not the case, or if you can't figure it out, please post your template file here (ZIP it up if the forum software prevents you from uploading php files).
This code throws the error I mentioned above.
Reading through these posts, I'd be interested to see an autonav block that 1.) Outputs nested lists and 2.) assigns a unique CSS class to each nav LI item.
Anyways...here's what I have that doesn't work:
<?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')) { $target = $ni->getTarget(); if ($target != '') { $target = 'target="' . $target . '"'; } if ($ni->isActive($c) || strpos($c->getCollectionPath(), $_c->getCollectionPath()) === 0) {
<? defined('C5_EXECUTE') or die("Access Denied."); $aBlocks = $controller->generateNav(); $c = Page::getCurrentPage(); $containsPages = false; $firstNavLi = true; $nh = Loader::helper('navigation'); //this will create an array of parent cIDs $inspectC=$c; $selectedPathCIDs=array( $inspectC->getCollectionID() ); $parentCIDnotZero=true; while($parentCIDnotZero){ $cParentID=$inspectC->cParentID; if(!intval($cParentID)){ $parentCIDnotZero=false;
This is the error I get when i do that:
Parse error: syntax error, unexpected T_ARRAY in /blocks/autonav/templates/custom_menu_compatible.php on line 69
THIS is how the autonav block should work right out of the box.
Here is the working output. I just transitioned this site to C5 from Joomla.
http://ribapalooza.com
Am I missing something?
Thanks,
Result is here: http://designsbytierney.com/levin-c5/facilities-and-services/...
https://raw.github.com/jordanlev/c5_clean_block_templates/master/aut...
(Save that file to YOURSITE/blocks/autonav/view.php).
It contains a ton of features from all over the forums and is very easy to customize as well. It even includes this "add a class for every item" feature, although it's disabled by default so you'll have to uncomment it (scroll down to the "DESIGNERS: CUSTOMIZE CSS CLASSES HERE..." section for that).
And I've also put up some other cleaned-up templates for the Form and Page List block, in case you're interested in those as well:
https://github.com/jordanlev/c5_clean_block_templates/...
-Jordan
Was that supposed to be part of the script you mentioned above, the first of the two added in your post above?
thanks,
Will look again.
http://c5blog.jordanlev.com/blog/2011/12/customizing-the-autonav-te...
Honestly, the way I'd recommend doing this, and all future code is to modify this:
And turn it into this:
//Disclaimer: I wrote the above code while posting, so it might have errors.