How do you create a sub-menu that shows just the parent, not the whole top level?

Permalink
Hi There,

Still getting my head around autonav but am having trouble embedding a couple of sidebar menus in my templates.

Sub-menu one:
A menu that shows the parent first (highlighted) then all the pages under the parent at level 1.

Sub-menu two:
A menu that only shows the parent (highlighted).

I have this in my template:
<ul class="s-nav">
   <?php
   $autonav = BlockType::getByHandle('autonav');
   $autonav->controller->orderBy = 'display_asc';
   $autonav->render('templates/sub_nav');
   ?>
</ul>


And this in my sub_nav.php template:
<?php 
   defined('C5_EXECUTE') or die("Access Denied.");
   $bt->controller->displayPages = 'above';
   $aBlocks = $controller->generateNav();
   $c = Page::getCurrentPage();
   $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) {


I've played around with the various 'top' 'above' settings but they both seem to display the entire top level.

Should I be using a non-autonav call to grab the parent page, then using autonav to display the pages at the current level maybe?

New to c5 so sorry if this easy.

Cheers

ben

 
ryan replied on at Permalink Best Answer Reply
ryan
Yeah, I would pull the current page's parent, then add a link using that. Something like:

$nh = Loader::helper('navigation');
$c = Page::getCurrentPage();
$topcID =  $c->getCollectionParentID();
if($topcID > 0) {
   $sectionHead = Page::getByID($topcID);
   echo '<div class="nav-section-head"><a href="'.$nh->getLinkToCollection($sectionHead).'">'.$sectionHead->getCollectionName()."</a></div>";
}
cmscss replied on at Permalink Reply
Beautiful - thanks mate.

For my own reference (incase I forget later on) I put this extra call above the autonav call in the page template.
ryan replied on at Permalink Reply
ryan
Yeah, that makes sense to me.
cmscss replied on at Permalink Reply
The only issue is that when this template is used on the parent page, it displays home instead if it's own page name.

Is there way to create a flexible menu that could be used on both parent pages as well as child pages?