Instantly share code, notes, and snippets.
MarkupSimpleNavigation Example for Bootstrap 2.3.2 Multilevel Navbar
<?php | |
/* | |
MarkupSimpleNavigation Example for Bootstrap 2.3.2 Multilevel Navbar | |
*/ | |
// load MarkupSimpleNavigation module | |
$nav = $modules->get("MarkupSimpleNavigation"); | |
/* SETUP HOOKs ------------- */ | |
// hook to have custom items markup | |
$nav->addHookAfter('getTagsString', null, 'customNavItems'); | |
function customNavItems(HookEvent $event){ | |
$item = $event->arguments('page'); | |
// first level items need additional attr | |
if($item->numChildren(true) && count($item->parents) < 2){ | |
$title = $item->get("title|name"); | |
$event->return = '<a href="#" class="dropdown-toggle" data-toggle="dropdown">' . $title . ' <b class="caret"></b></a>'; | |
} | |
// submenus don't need class and data attribs | |
if($item->numChildren(true) && count($item->parents) > 1){ | |
$event->return = '<a href="#">' . $item->get("title|name") . '</a>'; | |
} | |
} | |
// hook to add custom class to li's that have submenu | |
$nav->addHookAfter('getListClass', null, 'customListClass'); | |
function customListClass(HookEvent $event){ | |
$item = $event->arguments('page'); | |
// if current list item has children and is level 2 from root | |
if($item->numChildren(true) && count($item->parents) > 1){ | |
$event->return = ' dropdown-submenu'; // adds class to li | |
} | |
} | |
/* Render Navigation Markup ---------------- */ | |
$navMarkup = $nav->render( | |
array( | |
'max_levels' => 4, | |
'current_class' => 'active', | |
'has_children_class' => 'dropdown', // all li's that have children | |
'outer_tpl' => '<ul class="nav">||</ul>', // custom class | |
'inner_tpl' => '<ul class="dropdown-menu">||</ul>', // custom class for all submenu will get hooked for dropdown-submenu | |
) | |
); | |
?> | |
<div class="navbar"> | |
<div class="navbar-inner"> | |
<a class="brand" href="#">Menu</a> | |
<?php echo $navMarkup; ?> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment