Create a custom navigation menu based on page CIDs?

Permalink
I'd like to hardcode a main menu that displays a set of hand picked pages by pageCID (don't want to hardcode it via html in case the link name changes). I don't want to use a global exclude from nav since I want to be able to automatically generate a sitemap page using the autonav block (and avoid the breadcrumb bug).

I tried using:
$bt = BlockType::getByHandle('autonav');
$bt->controller->displayPages = 'custom';
$bt->controller->displayPagesCID = array('1', '118', '119', '121', '122', '160');
$bt->controller->orderBy = 'display_asc';
$bt->render('templates/main_menu');


I guess that's not the intended use as the only output I get from this is HOME.

As an alternative, perhaps there's a way to exclude certain page CIDs from within the template file when it iterates through all the items?

rickcigarette
 
jero replied on at Permalink Reply
jero
Why not use Jordanlev's Manual Nav addon?

http://www.concrete5.org/marketplace/addons/manual-nav/...
rickcigarette replied on at Permalink Reply
rickcigarette
Thanks! That will work... Next time I'll try to search the addons.
rickcigarette replied on at Permalink Best Answer Reply
rickcigarette
Actually, I have figured out a better way of doing this. I made a custom boolean attribute in the attributes section of the dashboard called hide_from_main_menu.

Then I made a "custom" main_menu.php template that encloses the menu construction from the default template with another if statement:
if (!$_c->getCollectionAttributeValue('hide_from_main_menu')) {
  if (!$_c->getCollectionAttributeValue('exclude_nav')) {
    //rest of the default template menu generating code...
  }
}

Then in the template I can use:
<?php
$bt = BlockType::getByHandle('autonav');
$bt->controller->displayPages = 'top';
$bt->controller->orderBy = 'display_asc';
$bt->controller->displaySubPages = 'relevant';
$bt->render('templates/main_menu');
?>

I think this is a more customizable solution than the Manual Nav plugin for this situation. If you have lots of pages you want to hide you could go about it doing the reverse. Having an attribute for "Show in X menu" and adjust the if statement accordingly...
mjames757 replied on at Permalink Reply
What if I wanted to do this same thing based on whether or not a user is logged in a member(not in edit mode either). So my menu has a link to the members page. When a member is already logged in, I want that same menu item to display: Logout. Presently, I am using the following block of code to accomplish the task in the header, but what I really want this to work directly with the NAV menu. Any ideas?

<?php
$uinfo = new User();
if($uinfo->IsLoggedIn()){ ?>
<a href="<?php echo DIR_REL?>/index.php/login/-/logout">Logout</a> | <a href="<?php echo $this->url('/profile')?>">My Profile</a>
<?php
} else { ?>
<a href="<?php echo $this->url('/login')?>">Login</a> | <a href="<?php echo $this->url('/register')?>">Register</a>
<?php }?>