Building a menu with Sigma
| From: | Birgir Stefansson | Date: | Fri, 05 Sep 2003 15:59:52 +0000 |
| Subject: | Building a menu with Sigma | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-7600@lists.php.net to get a copy of this message | ||
Hi.
I'm trying to build a menu and rendering it with HTML_Template_Sigma. I
run into problems when I try to make a more complex menu than the one
shown in the docs for Sigma in CVS which I am building upon.
Here's the deal :
I want to create the menu in the following manner
Entry(1)
- SubEntry(1)(1)
- SubEntry(1)(2)
- SubSubEntry(1)(2)(1)
- SubSubEntry(1)(2)(2)
- SubEntry(1)(3)
Entry(2)
Entry(3)
but end up with the following menu
Entry(1)
Entry(2)
Entry(3)
- SubEntry(1)(1)
- SubEntry(1)(2)
- SubEntry(1)(3)
- SubSubEntry(1)(2)(1)
- SubSubEntry(1)(2)(2)
which you can see is not what I am expecing.
I haven't been using Sigma for that long so I'm hoping that I'm just
making some mistake and that creating this sort of menu is still
possible using a template.
Here is the part where I try to render the menu
foreach($entries as $entry) {
$tpl->setVariable(array('menu_title' => $entry['title'],
'menu_url'
=> $entry['url']));
if($entry['type'] == MENU_ENTRY_ACTIVEPATH) {
$tpl->parse('menu_entry_activepath');
} else {
$tpl->parse('menu_entry_inactive');
}
if(($entry['type'] == MENU_ENTRY_ACTIVEPATH) && $entry['sub']) {
foreach($entry['sub'] as $subentry) {
$tpl->setVariable(array('menu_title' => $subentry['title'],
'menu_url' => $subentry['url']));
if($subentry['type'] == MENU_ENTRY_INACTIVE) {
$tpl->parse('menu_subentry_inactive');
} else if($subentry['type'] == MENU_ENTRY_ACTIVEPATH) {
$tpl->parse('menu_subentry_activepath');
} else {
$tpl->parse('menu_subentry_active');
}
if((($subentry['type'] == MENU_ENTRY_ACTIVEPATH) ||
($subentry['type'] == MENU_ENTRY_ACTIVE)) && $subentry['sub']) {
foreach($subentry['sub'] as $subsubentry) {
$tpl->setVariable(array('menu_title' =>
$subsubentry['title'], 'menu_url' => $subsubentry['url']));
if($subsubentry['type'] == MENU_ENTRY_INACTIVE) {
$tpl->parse('menu_subsubentry_inactive');
} else if($subsubentry['type'] ==
MENU_ENTRY_ACTIVEPATH) {
$tpl->parse('menu_subsubentry_activepath');
} else {
$tpl->parse('menu_subsubentry_active');
}
}
}
}
}
}
$tpl->parse('menu');
Here is the menu block from the template
<!-- BEGIN menu -->
<table>
<!-- BEGIN menu_topentry_activepath -->
<tr><td bgcolor="#124274"> <a
href="{menu_url}"><font
color=white>{menu_title}</a></font><br></td></tr>
<!-- END menu_topentry_activepath -->
<!-- BEGIN menu_topentry_inactive -->
<tr><td bgcolor="#E4E4E4"> <a
href="{menu_url}">{menu_title}</a><br></font></td></tr>
<!-- END menu_topentry_inactive -->
<!-- BEGIN menu_subentry_inactive -->
<tr><td bgcolor="#E4E4E4"> <a
href="{menu_url}">{menu_title}</a><br></td></tr>
<!-- END menu_subentry_inactive -->
<!-- BEGIN menu_subentry_activepath -->
<tr><td bgcolor="#E4E4E4"> <a
href="{menu_url}">{menu_title}</a><br></td></tr>
<!-- END menu_subentry_activepath -->
<!-- BEGIN menu_subentry_active -->
<tr><td bgcolor="#E4E4E4"> <a
href="{menu_url}"><b>{menu_title}</b></a><br></td></tr>
<!-- END menu_subentry_active -->
<!-- BEGIN menu_subsubentry_inactive -->
<tr><td
bgcolor="#E4E4E4"> <a
href="{menu_url}">{menu_title}</a><br></td></tr>
<!-- END menu_subsubentry_inactive -->
<!-- BEGIN menu_subsubentry_activepath -->
<tr><td
bgcolor="#E4E4E4"> <a
href="{menu_url}">{menu_title}</a><br></td></tr>
<!-- END menu_subsubentry_activepath -->
<!-- BEGIN menu_subsubentry_active -->
<tr><td
bgcolor="#E4E4E4"> <a
href="{menu_url}"><b>{menu_title}</b></a><br></td></tr>
<!-- END menu_subsubentry_active -->
</table>
<!-- END menu -->
I was experimenting with HTML_Menu which does what I want to do but has
html code inside the class which is not what I want. I want to be able
to give a template to a designer and have the designer be able to alter
everthing without having to go in and edit html lurking in my code.
What am I doing wrong ?
Is there another way to do this ?
Thank you!
Regards,
Birgir