DirectTreeRenderer methods syntax
| From: | John B Dougherty | Date: | Thu, 30 Oct 2008 13:47:29 +0000 |
| Subject: | DirectTreeRenderer methods syntax | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-29386@lists.php.net to get a copy of this message | ||
I am trying to configure DirectTreeRenderer to output a menu so
it will render a ul required by
http://accessat.c-net.us/articles/menu/h_drop-down-menu.html
and
http://accessat.c-net.us/articles/menu/v_drop-down-menu.html
for DHTML Menu
1. Main menu should be an unordered list (<ul>) with class="mainmenu"
use DirectTreeRenderer::setLevelTemplate()
2. Each main menu item should be:
- an <li> with id="mainmenu#" where # is sequential, starting at 1
use DirectTreeRenderer::setItemTemplate()
- an anchor <a> with class="mainmenu"
use DirectTreeRenderer::setEntryTemplate()
setLevelTemplate() works (just uses a string literal)
setItemTemplate() is not getting the placeholder from menu structure
setEntryTemplate() does not seem to affect the output at all.
I am pretty sure I am not passing params correctly to setItemTemplate() and
setEntryTemplate()
thank you! John
http://perfectmorass.info/menu_render.php
here's the source:
<?php
ini_set(
"include_path", (
dirname(__FILE__) . "/pear/PEAR/" .
":" .
ini_get("include_path")
)
);
// Load the class
require_once 'HTML/Menu.php';
require_once 'HTML/Menu/DirectTreeRenderer.php';
require_once './data/menu.php';
// Instantiate the menu object, we presume that $data contains menu
structure
$menu =& new HTML_Menu($data);
$renderer =& new HTML_Menu_DirectTreeRenderer();
$renderer->setLevelTemplate('<ul
class="mainmenu">','</ul>');
$renderer->setItemTemplate('<li id="{id}">','</li>');
$renderer->setEntryTemplate('type','<a href="{url}"
class="{class}">{title}</a>');
$menu->render($renderer, 'tree');
// Output the menu
echo $renderer->toHtml()
?>
here's the output source:
<ul class="mainmenu">
<li id="{id}"><a href="/index.html">Home</a></li>
<li id="{id}"><a href="/cms/index.php">cms</a></li>
<li id="{id}"><a
href="/phpfreechat/index.php">chat</a></li>
<li id="{id}"><a
href="/tiddly/index.php">tiddly</a></li>
<li id="{id}"><a href="/vlc/index.html">vlc</a></li>
<li id="{id}"><a
href="/geo_hack/index.php">geo-hacks</a></li>
<li id="{id}"><a
href="/thuper/index.html">thuper</a></li>
<li id="{id}"><a href="/firephp/">firephp</a></li>
<li id="{id}"><a href="/Nutmeg/">Nutmeg</a></li>
</ul>
here is the menu structure:
<?php
$data = array(
1 => array(
'title' => 'Home',
'url' => '/index.html',
'desc' => 'perfect home',
'id' => 'mainmenu1',
'class' => 'mainmenu',
),
2 => array(
'title' => 'cms',
'url' => '/cms/index.php',
'desc' => 'joomla!',
'id' => 'mainmenu2',
'class' => 'mainmenu',
),
3 => array(
'title' => 'chat',
'url' => '/phpfreechat/index.php',
'desc' => 'phpfreechat',
'id' => 'mainmenu3',
'class' => 'mainmenu',
),
4 => array(
'title' => 'tiddly',
'url' => '/tiddly/index.php',
'desc' => 'php tiddly wiki',
'id' => 'mainmenu4',
'class' => 'mainmenu',
),
5 => array(
'title' => 'vlc',
'url' => '/vlc/index.html',
'desc' => 'streaming media',
'id' => 'mainmenu5',
'class' => 'mainmenu',
),
6 => array(
'title' => 'geo-hacks',
'url' => '/geo_hack/index.php',
'desc' => 'mapping',
'id' => 'mainmenu6',
'class' => 'mainmenu',
),
7 => array(
'title' => 'thuper',
'url' => '/thuper/index.html',
'desc' => 'embedded videos',
'id' => 'mainmenu7',
'class' => 'mainmenu',
),
8 => array(
'title' => 'firephp',
'url' => '/firephp/',
'desc' => 'debug php with firebug',
'id' => 'mainmenu8',
'class' => 'mainmenu',
),
9 => array(
'title' => 'Nutmeg',
'url' => '/Nutmeg/',
'desc' => 'sailboat',
'id' => 'mainmenu9',
'class' => 'mainmenu',
)
);
?>