How to get submenus to appear in autonav template
Permalink
I have built a site template where I am wanting submenus to display for the autonav block. I am unsure how to add submenus to display in an autonav template.
I have hardcoded the autonav block to header.php with the following:
I then have the following in mytemplate_menu.php
I need to add code to allow the submenu items to display (nested list) in this format:
Any assistance in what I need to add to my autonav template would be greatly appreciated.
Thanks
I have hardcoded the autonav block to header.php with the following:
<?php $bt_main = BlockType::getByHandle('autonav'); $bt_main->controller->displayPages = 'top'; $bt_main->controller->orderBy = 'display_asc'; $bt_main->controller->displaySubPages = 'all'; $bt_main->controller->displaySubPageLevels = 'all'; $bt_main->render('templates/mytemplate_menu.php); ?>
I then have the following in mytemplate_menu.php
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); $navItems = $controller->getNavItems(); ?> <ul id="nav"> <li><a href="/index.php"><span class="home_icon"></span></a></li> <?php foreach ($navItems as $ni) { $classes = array(); if ($ni->isCurrent) { $classes[] = 'nav-selected'; } if ($ni->inPath) { $classes[] = 'active'; } if ($ni->isFirst) { $classes[] = 'first';
Viewing 15 lines of 23 lines. View entire code block.
I need to add code to allow the submenu items to display (nested list) in this format:
<div id="menu"> <ul> <li><a href="index.php">Home<span></span></a></li> <li><a href="/services">Services<span></span></a> <div> <ul> <li><a href="/services/services1"><span>Services 1</span></a></li> <li><a href="/services/services2"><span>Services 2</span></a></li> <li><a href="#" class="last_submenu_item"><span>Multi-Level Menu</span></a> <div class='subsub_menu'> <ul> <li class=""><a href="#"><span>Item One</span></a></li> <li class=""><a href="#" class="last_submenu_item"><span>Item Two</span></a> <div class='subsubsub_menu'> <ul>
Viewing 15 lines of 28 lines. View entire code block.
Any assistance in what I need to add to my autonav template would be greatly appreciated.
Thanks
You need to change the mytemplate_menu.php page. Here is the code.
Viewing 15 lines of 32 lines. View entire code block.
Thanks ronyDdeveloper.
I am getting the following error:
Parse error: syntax error, unexpected '<' in /hsphere/local/home/domain/domain.com/blocks/autonav/templates/header_menu_4d.php on line 35
This coincides with:
Thanks
I am getting the following error:
Parse error: syntax error, unexpected '<' in /hsphere/local/home/domain/domain.com/blocks/autonav/templates/header_menu_4d.php on line 35
This coincides with:
<?php } ?> </ul>
Thanks
Ohhh! I'm sorry. I've forgotten to close the php tag.
Just put tag before line 35 that is
Rony
Just put
?>
<?php } ?> </ul>
Rony
Thanks again for your help.
That fixed the error however it is not displaying the submenu code.
It is is displaying as:
Instead of:
It appears to be ignoring:
Thanks again. I really appreciate your help.
That fixed the error however it is not displaying the submenu code.
It is is displaying as:
<li class="first"> <a class="first" href="/" target="_self">Home</a> </li> <li class="sub-menu"> <a class="sub-menu" href="/about/" target="_self">About</a> </li> <li class="first"> <a class="first" href="/about/our-people/" target="_self">Our People</a> </li>
Instead of:
<li class="first"> <a class="first" href="/" target="_self">Home</a> </li> <li> <a class="sub-menu" href="/about/" target="_self">About</a> <div> <ul> <li> <a href="/about/our-people/" target="_self"><span>Our People</span></a> </li> </ul> </div>
It appears to be ignoring:
<?php if ($rs->hasSubmenu) { echo '<div><ul>'; } else { echo '</li>'.str_repeat('</ul></div></li>', $rs->subDepth); } ?>
Thanks again. I really appreciate your help.
The object was not same as others.
Rony
***$rs->hasSubmenu [wrong] ***$ni->hasSubmenu [right] <?php if ($ni->hasSubmenu) { echo '<ul>'; } else { echo '</li>'.str_repeat('</ul></li>', $rs->subDepth); } ?>
Rony
Thanks again.
That fixed the problem. I changed the code to:
Is there anyway of hiding the third level items? The site in question has third and fourth level items. That are displaying. I am wanting to display these in a sidebar autonav so do not want to set them as hide in autonav in page properties.
Thanks
That fixed the problem. I changed the code to:
<?php if ($ni->hasSubmenu) { echo '<div><ul>'; } else { echo '<li>'.str_repeat('</ul></div></li>', $ni->subDepth); } ?>
Is there anyway of hiding the third level items? The site in question has third and fourth level items. That are displaying. I am wanting to display these in a sidebar autonav so do not want to set them as hide in autonav in page properties.
Thanks
I'm not sure whether it is 100% correct as I've not tested it, but I think this piece of code will work for you.
Rony
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); $navItems = $controller->getNavItems(); ?> <ul id="nav"> <li><a href="/index.php"><span class="home_icon"></span></a></li> <?php foreach ($navItems as $ni) { $classes = array(); if ($ni->isCurrent) { $classes[] = 'nav-selected'; } if ($ni->inPath) { $classes[] = 'active'; } if ($ni->isFirst) { $classes[] = 'first';
Viewing 15 lines of 35 lines. View entire code block.
Rony
Thanks again.
No it didn't work.
I have just set the autonav to:
Display pages: top level
Subpages to display: all
Sub-page Levels: display a custom amount
levels: 1.
Thanks again for your very generous help. I now have the ability to add a menu with submenus (single level).
No it didn't work.
I have just set the autonav to:
Display pages: top level
Subpages to display: all
Sub-page Levels: display a custom amount
levels: 1.
Thanks again for your very generous help. I now have the ability to add a menu with submenus (single level).
For those that may find it helpful the complete code for the autonav template with submenu items is:
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); $navItems = $controller->getNavItems(); ?> <ul id="nav"> <li><a href="/index.php"><span class="home_icon"></span></a></li> <?php foreach ($navItems as $ni) { $classes = array(); if ($ni->isCurrent) { $classes[] = 'nav-selected'; } if ($ni->inPath) { $classes[] = 'active'; } if ($ni->isFirst) { $classes[] = 'first';
Viewing 15 lines of 33 lines. View entire code block.