Skip to content

Instantly share code, notes, and snippets.

@jeroenherczeg
Forked from kkamkou/horizontal.phtml
Created June 19, 2012 12:44
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save jeroenherczeg/2953935 to your computer and use it in GitHub Desktop.
Save jeroenherczeg/2953935 to your computer and use it in GitHub Desktop.
Zend Navigation for the Twitter Bootstrap
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
protected function _initNavigation() {
// make sure the layout is loaded
$this->bootstrap('layout');
// get the view of the layout
$layout = $this->getResource('layout');
$view = $layout->getView();
//load the navigation xml
$config = new Zend_Config_Xml(APPLICATION_PATH.'/configs/navigation.xml','nav');
// pass the navigation xml to the zend_navigation component
$nav = new Zend_Navigation($config);
// pass the zend_navigation component to the view of the layout
$view->navigation($nav);
}
}
<?php
/**
* @authors Kanstantsin A Kamkou (2ka.by); Jeroen Herczeg
*/
$html = array();
$html[] ='<div class="navbar navbar-fixed-top">';
$html[] =' <div class="navbar-inner">';
$html[] =' <div class="container">';
$html[] =' <ul class="nav">';
foreach ($this->container as $page) {
// visibility of the page
if (!$page->isVisible()) {
continue;
}
// dropdown
$dropdown = !empty($page->pages);
// header
$html[] = '<li' . ($dropdown ? ' class="dropdown"' : '') . '>';
$html[] = '<a href="' . ($dropdown ? '#' : $page->getHref()) . '" '
. 'class="dropdown-toggle" data-toggle="dropdown">';
$html[] = $page->getLabel();
if ($dropdown) {
$html[] = '<b class="caret"></b>';
}
$html[] = '</a>';
if (!$dropdown) {
$html[] = '</li>';
continue;
}
$html[] = '<ul class="dropdown-menu">';
foreach ($page->pages as $subpage) {
// visibility of the sub-page
if (!$subpage->isVisible()) {
continue;
}
if ($subpage->getLabel() == 'divider') {
$html[] = '<li class="divider"></li>';
continue;
}
$html[] = '<li' . ($subpage->isActive() ? ' class="active"' : '') . '>';
$html[] = '<a href="' . $subpage->getHref() . '">';
if ($subpage->get('icon')) {
$html[] = '<i class="icon-' . $subpage->get('icon') . '"></i>';
}
$html[] = $subpage->getLabel();
$html[] = "</a>";
$html[] = "</li>";
}
$html[] = "</ul>";
$html[] = "</li>";
}
$html[] = '</ul>';
$html[] = '</div>';
$html[] = '</div>';
$html[] = '</div>';
echo join(PHP_EOL, $html);
$this->navigation()->menu()->setPartial('partials/horizontal.phtml');
echo $this->navigation()->menu()->render();
<?xml version="1.0" encoding="UTF-8"?>
<configdata>
<nav>
<dashboard>
<label>Dashboard</label>
<uri>/</uri>
</dashboard>
<myprofile>
<label>My Profile</label>
<uri></uri>
<pages>
<editprofile>
<label>Edit my profile</label>
<uri>/user/profile</uri>
</editprofile>
<changepassword>
<label>Change my password</label>
<uri>/user/password</uri>
</changepassword>
<divider>
<label>divider</label>
<uri></uri>
</divider>
<logout>
<label>Log out</label>
<uri>/index/logout</uri>
</logout>
</pages>
</myprofile>
<admin>
<label>Administration</label>
<uri>/admin</uri>
</admin>
</nav>
</configdata>
<?php
/**
* @authors Kanstantsin A Kamkou (2ka.by); Jeroen Herczeg
*/
$html = array('<ul class="nav nav-list">');
foreach ($this->container as $page) {
// show only the current branch and the visible item
if (!$page->isVisible()
|| ($this->menu()->getOnlyActiveBranch() && !$page->isActive(true))) {
continue;
}
// header
$html[] = '<li class="nav-header">';
$html[] = $page->getLabel();
$html[] = "</li>";
if (!empty($page->pages)) {
foreach ($page->pages as $subpage) {
// visibility of the sub-page
if (!$subpage->isVisible()) {
continue;
}
if ($subpage->getLabel() == 'divider') {
$html[] = '<li class="divider"></li>';
continue;
}
$html[] = '<li' . ($subpage->isActive() ? ' class="active"' : '') . '>';
$html[] = '<a href="' . $subpage->getHref() . '">';
if ($subpage->get('icon')) {
$html[] = '<i class="icon-' . $subpage->get('icon') . '"></i>';
}
$html[] = $subpage->getLabel();
$html[] = "</a>";
$html[] = "</li>";
}
}
}
$html[] = '</ul>';
$html[] = '</div>';
$html[] = '</div>';
$html[] = '</div>';
echo join(PHP_EOL, $html);
@webdevilopers
Copy link

Is there a recursive example to render dropdown menus for submenus of submenus?
https://gist.github.com/kkamkou/1892557

@binhpv186
Copy link

No adding translate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment