Last active
May 27, 2022 16:12
-
-
Save kkamkou/1892557 to your computer and use it in GitHub Desktop.
Zend Navigation for the Twitter Bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author Kanstantsin A Kamkou (2ka.by) | |
* History: | |
* - 21.08.2012 Bootstrap 2.1.0 corrections | |
* - 31.03.2013 Acl check added | |
*/ | |
$html = array('<ul class="nav">'); | |
foreach ($this->container as $page) { | |
// visibility of the page | |
if (!$page->isVisible() || !$this->navigation()->accept($page)) { | |
continue; | |
} | |
// dropdown | |
$dropdown = !empty($page->pages); | |
// header | |
$html[] = '<li' . ($dropdown ? ' class="dropdown"' : '') . '>'; | |
if (!$dropdown) { | |
$html[] = '<a href="' . $page->getHref() . '">'; | |
} else { | |
$html[] = '<a href="#" 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() || !$this->navigation()->accept($subPage, false)) { | |
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>'; | |
echo join(PHP_EOL, $html); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author Kanstantsin A Kamkou (2ka.by) | |
*/ | |
$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->navigation()->accept($page) | |
|| ($this->menu()->getOnlyActiveBranch() && !$page->isActive(true))) { | |
continue; | |
} | |
// header | |
$html[] = '<li class="nav-header">'; | |
$html[] = $page->getLabel(); | |
$html[] = "</li>"; | |
foreach ($page->pages as $subPage) { | |
// visibility of the sub-page | |
if (!$subPage->isVisible() || !$this->navigation()->accept($subPage, false)) { | |
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>'; | |
echo join(PHP_EOL, $html); |
Is there a recursive example to render dropdown menus for submenus of submenus?
https://gist.github.com/jeroenherczeg/2953935
@webdevilopers Create a gist with your navigation config. And post link here.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how i use ?