HTML Menu: nested trees
| From: | Uwe Mindrup | Date: | Fri, 19 Sep 2003 06:03:10 +0000 |
| Subject: | HTML Menu: nested trees | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-7909@lists.php.net to get a copy of this message | ||
Hi,
is it possible to generate nested menu trees like this:
<ul>
<li>Startpage</li>
<li>Entry 2
<ul>
<li>Entry 2.1</li>
<li>Entry 2.2</li>
</ul>
<li>Entry 3</li>
</ul>
with the existing HTML Menu package?
I have tried it with serveral methods, but only with a extension of
_menuType i had success. I added a "tree_recursive" element to _menuType
and added a Menu->_renderTreeRecursive with the following code:
/**
* Renders the tree menu ('tree' and 'sitemap') with recursion
*
* @access private
* @param array (sub)menu being rendered
* @param int current depth in the tree structure
*/
function _renderTreeRecursive($menu, $level = 0)
{
foreach ($menu as $node_id => $node) {
$type = $this->_findNodeType($node_id, $node['url'], $level);
$this->_renderer->renderEntry($node, $level, $type);
// follow the subtree if the active menu item is in it or if we
want the full menu
if (('sitemap' == $this->_menuType ||
HTML_MENU_ENTRY_INACTIVE != $type) && isset($node['sub'])) {
$this->_renderTreeRecursive($node['sub'], $level + 1);
}
$this->_renderer->finishRow($level);
}
$this->_renderer->finishMenu($level);
}
Needed is of course an adapted renderer package, but that is very simple.
Or is there a more elegant method to generate the above structure of a menu
with the HTML Menu package?
--
Uwe Mindrup, Ludwigsburg (Germany)