Exclude from Main Nav but not Sidebar Nav
PermalinkMy subpages have a sidebar nav the shows pages starting at the second level and shows pages also three levels deep.
There is one section of my site that I do NOT want the 3rd level items to show in the main navigation, however I DO need them to show on the subpage sidebar nav.
Anyone know of I way I can do this?
Thanks!
foreach ($navItems as $ni) { $_c = $ni->cObj; if ($_c->getAttribute('my_attribute_1')){ } else { echo '<li class="' . $ni->classes . '">'; //opens a nav item echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $ni->name . '</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) } }}
I think it would work, but not sure how efficient or practical it is.
The only problem I have with this approach is that the autonav still has to load the pages I don't want...which at this point is a couple dozen pages, but it will likely be a hundred or so over the next year or two.
This poses performance problems.
The first park works, to see if the nav item is of a certain page type:
if($ni->cObj->getCollectionTypeHandle() == 'case_study') { }
But this part here, where the autonav detects child pages and decides to open a submenu still fires. This ends up nesting every nav item inside the previous one:
if ($ni->hasSubmenu) { //this part results in TRUE even though I'm not displaying the children. 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) }
On my Main Nav, I used the attribute "exclude_subpages_from_nav" so the third level items would not show up under that one secion.
Then, on my Sidebar nav, I created a custom template that uses this line in the beginning:
$navItems = $controller->getNavItems(true);
The TRUE argument here makes the autonav ignore the Exclude attributes.
This works because as of right now, I don't think there are any nav items that would show up in the side bar that need to be excluded.
If so, then I need to find a better solution...
foreach ($navItems as $ni) { $_c = $ni->cObj; if($ni->cObj->getCollectionTypeHandle() == 'blank'){ } else { echo '<li class="' . $ni->classes . '">'; //opens a nav item echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $ni->name . '</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) } }
foreach ($navItems as $ni) { $_c = $ni->cObj; if ($_c->getCollectionTypeHandle('blank')) { } else //you may have missed this else statement and surrounding {} tags below { echo '<li class="' . $ni->classes . '">'; //opens a nav item echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $ni->name . '</a>'; if ($ni->hasSubmenu) { echo '<ul>'; //opens a dropdown sub-menu } else
If I add echo 'true'; to your first if statement, I get every single nav item to echo out true.
When I change your first IF statement to be this instead:
if ($ni->cObj->getCollectionTypeHandle() == 'case_study') {
I get all my nav items nested again on that third level.
Here is exactly what I have in my template:
foreach ($navItems as $ni) { $_c = $ni->cObj; if ($ni->cObj->getCollectionTypeHandle() == 'case_study') { // echo 'true'; } else //you may have missed this else statement and surrounding {} tags below { echo '<li class="' . $ni->classes . '">'; //opens a nav item echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '">' . $ni->name . '</a>'; if ($ni->hasSubmenu) { echo '<ul>'; //opens a dropdown sub-menu } else
1. Have you considered using a pagelist block for the sidebar nav instead of an "autonav" block. Then you could use the "exclude from nav"(all third level pages) and "exclude from pagelist"(all top level pages) attributes to get the desired result.
OR -- since it sounds like you want to include the third tier in the main nav on some pages, but not others.
2. Create one or two custom templates for the autonav block:http://c5blog.jordanlev.com/blog/2011/12/customizing-the-autonav-te...
For the record, this code has been merged into the core, so you can just copy concrete/blocks/autonav/view.php and get the same result.
My personal approach here would be two templates:
exclude top:
exclude third tier:
Hope this helps - RJ