I want to customize my menus, but since I want it to work with the html/css/javascript code I've already written and tested I want to get the system to output the menu in html as I want it. Actually what I need is quite simple. I don't really want to try to customize someone else's module and I'd rather not build one. After some digging around I figured out that I could override the theme_menu_links method in my template.php file. Now that's exactly what I need... I got really excited but I must have some things missing/misunderstood.
what I have in the menu system under primary links: primary links - menu item 1 - menu 1 subitem 1 - menu 1 subitem 2 - menu item 2 - menu 2 subitem 1
etc - fairly standard
What I need to output is the following:
<ul id="nav1" class="nav"> <li><a href="#">menu item 1</a> <ul> <li><a href="#">menu 1 subitem 1</a></li> <li><a href="#">menu 1 subitem 2</a></li> </ul> </li> </ul> <ul id="nav2" class="nav"> <li>menu item 2 <ul> <li><a href="#">menu 2 subitem 1</a></li> </ul> </li> </ul>
etc. - also pretty straight forward.
SO - I put in page.tpl.php the following: <?php print theme('menu_links', $primary_links); ?>
and put in template.php the following: function tpg_menu_links($links){ if (!count($links)) { return ''; } $level_tmp = explode('-', key($links)); $level = $level_tmp[0]; $output = "<ul id="nav" class="nav">\n"; foreach ($links as $index => $link) { $output .= "<li>". l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment']) ."</li>\n"; } $output .= '</ul>';
return $output; } ?>
Which is basically a modified version of theme_menu_links in menu.inc
It works as a start, but there are a couple of issues. 1. even though my class attribute in $output is hard coded, it's still being replaced by class="active" when you're on the page. Not a disaster, i can always modify my css to do the same thing for class="active" as class="nav". 2. this is the bigger issue. It's not outputting the subitems. I'd be happy to add in the proper call in the foreach loop to either call another function that i also override or to load them directly in here if anyone can point me in the direction of what i need to call in order to load them.
Making some progress here. I've realized that to some extent what I want to do is override theme_menu_tree and theme_menu_item. That gives me some of the control I need BUT the default menu system still has extra junk I don't want (such as a Primary links header) AND I need two types of menu trees that display different things - one horizontal in the top (primary links) and one vertical down the left (current section and its children).
so far i think menus are a pain in the ass in drupal. a tradeoff for the power but I think the multiple meanings that the word "menu" has in drupal just adds to the confusion of it all. What I need is really not that complicated, but it's becoming incredibly complicated fast.
sander-martijn wrote:
I want to customize my menus, but since I want it to work with the html/css/javascript code I've already written and tested I want to get the system to output the menu in html as I want it. Actually what I need is quite simple. I don't really want to try to customize someone else's module and I'd rather not build one. After some digging around I figured out that I could override the theme_menu_links method in my template.php file. Now that's exactly what I need... I got really excited but I must have some things missing/misunderstood.
what I have in the menu system under primary links: primary links
- menu item 1
- menu 1 subitem 1
- menu 1 subitem 2
- menu item 2
- menu 2 subitem 1
etc - fairly standard
What I need to output is the following:
<ul id="nav1" class="nav"> <li><a href="#">menu item 1</a> <ul> <li><a href="#">menu 1 subitem 1</a></li> <li><a href="#">menu 1 subitem 2</a></li> </ul> </li> </ul> <ul id="nav2" class="nav"> <li>menu item 2 <ul> <li><a href="#">menu 2 subitem 1</a></li> </ul> </li> </ul>
etc. - also pretty straight forward.
SO - I put in page.tpl.php the following:
<?php print theme('menu_links', $primary_links); ?>
and put in template.php the following: function tpg_menu_links($links){ if (!count($links)) { return ''; } $level_tmp = explode('-', key($links)); $level = $level_tmp[0]; $output = "<ul id="nav" class="nav">\n"; foreach ($links as $index => $link) { $output .= "<li>". l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment']) ."</li>\n"; } $output .= '</ul>';
return $output; } ?>
Which is basically a modified version of theme_menu_links in menu.inc
It works as a start, but there are a couple of issues.
- even though my class attribute in $output is hard coded, it's still
being replaced by class="active" when you're on the page. Not a disaster, i can always modify my css to do the same thing for class="active" as class="nav". 2. this is the bigger issue. It's not outputting the subitems. I'd be happy to add in the proper call in the foreach loop to either call another function that i also override or to load them directly in here if anyone can point me in the direction of what i need to call in order to load them.
You can use theme_menu_tree and theme_menu_item, but you will theme every menu that passes through the menu system that way. What I like to do is do my own theme for the menu items on your page.tpl.php <?php print theme('my_menu_themeing', $primary_links); ?>
inside your template.tpl.php function THEME_NAME_my_menu_themeing($links) { $output; .. custom html with my menu ... return $output; }
see it that works for you. Eric.
sander-martijn wrote:
Making some progress here. I've realized that to some extent what I want to do is override theme_menu_tree and theme_menu_item. That gives me some of the control I need BUT the default menu system still has extra junk I don't want (such as a Primary links header) AND I need two types of menu trees that display different things - one horizontal in the top (primary links) and one vertical down the left (current section and its children).
so far i think menus are a pain in the ass in drupal. a tradeoff for the power but I think the multiple meanings that the word "menu" has in drupal just adds to the confusion of it all. What I need is really not that complicated, but it's becoming incredibly complicated fast.
sander-martijn wrote:
I want to customize my menus, but since I want it to work with the html/css/javascript code I've already written and tested I want to get the system to output the menu in html as I want it. Actually what I need is quite simple. I don't really want to try to customize someone else's module and I'd rather not build one. After some digging around I figured out that I could override the theme_menu_links method in my template.php file. Now that's exactly what I need... I got really excited but I must have some things missing/misunderstood.
what I have in the menu system under primary links: primary links
- menu item 1
- menu 1 subitem 1
- menu 1 subitem 2
- menu item 2
- menu 2 subitem 1
etc - fairly standard
What I need to output is the following:
<ul id="nav1" class="nav"> <li><a href="#">menu item 1</a> <ul> <li><a href="#">menu 1 subitem 1</a></li> <li><a href="#">menu 1 subitem 2</a></li> </ul> </li> </ul> <ul id="nav2" class="nav"> <li>menu item 2 <ul> <li><a href="#">menu 2 subitem 1</a></li> </ul> </li> </ul>
etc. - also pretty straight forward.
SO - I put in page.tpl.php the following:
<?php print theme('menu_links', $primary_links); ?>
and put in template.php the following: function tpg_menu_links($links){ if (!count($links)) { return ''; } $level_tmp = explode('-', key($links)); $level = $level_tmp[0]; $output = "<ul id="nav" class="nav">\n"; foreach ($links as $index => $link) { $output .= "<li>". l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment']) ."</li>\n"; } $output .= '</ul>';
return $output; } ?>
Which is basically a modified version of theme_menu_links in menu.inc
It works as a start, but there are a couple of issues.
- even though my class attribute in $output is hard coded, it's still
being replaced by class="active" when you're on the page. Not a disaster, i can always modify my css to do the same thing for class="active" as class="nav". 2. this is the bigger issue. It's not outputting the subitems. I'd be happy to add in the proper call in the foreach loop to either call another function that i also override or to load them directly in here if anyone can point me in the direction of what i need to call in order to load them.
--
sander-martijn mailto:sander@sander-martijn.com interface developer | architect sander@sander-martijn.com mailto:sander@sander-martijn.com www.sander-martijn.com http://www.sander-martijn.com
Forgot to to add that you will have to get intimate with the $primary_links array, but its not difficult. Throw in a print_r($links) and you have all you need.
Eric Mckenna wrote:
You can use theme_menu_tree and theme_menu_item, but you will theme every menu that passes through the menu system that way. What I like to do is do my own theme for the menu items on your page.tpl.php
<?php print theme('my_menu_themeing', $primary_links); ?>
inside your template.tpl.php function THEME_NAME_my_menu_themeing($links) { $output; .. custom html with my menu ... return $output; }
see it that works for you. Eric.
sander-martijn wrote:
Making some progress here. I've realized that to some extent what I want to do is override theme_menu_tree and theme_menu_item. That gives me some of the control I need BUT the default menu system still has extra junk I don't want (such as a Primary links header) AND I need two types of menu trees that display different things - one horizontal in the top (primary links) and one vertical down the left (current section and its children). so far i think menus are a pain in the ass in drupal. a tradeoff for the power but I think the multiple meanings that the word "menu" has in drupal just adds to the confusion of it all. What I need is really not that complicated, but it's becoming incredibly complicated fast.
sander-martijn wrote:
I want to customize my menus, but since I want it to work with the html/css/javascript code I've already written and tested I want to get the system to output the menu in html as I want it. Actually what I need is quite simple. I don't really want to try to customize someone else's module and I'd rather not build one. After some digging around I figured out that I could override the theme_menu_links method in my template.php file. Now that's exactly what I need... I got really excited but I must have some things missing/misunderstood.
what I have in the menu system under primary links: primary links
- menu item 1
- menu 1 subitem 1
- menu 1 subitem 2
- menu item 2
- menu 2 subitem 1
etc - fairly standard
What I need to output is the following:
<ul id="nav1" class="nav"> <li><a href="#">menu item 1</a> <ul> <li><a href="#">menu 1 subitem 1</a></li> <li><a href="#">menu 1 subitem 2</a></li> </ul> </li> </ul> <ul id="nav2" class="nav"> <li>menu item 2 <ul> <li><a href="#">menu 2 subitem 1</a></li> </ul> </li> </ul>
etc. - also pretty straight forward.
SO - I put in page.tpl.php the following:
<?php print theme('menu_links', $primary_links); ?>
and put in template.php the following: function tpg_menu_links($links){ if (!count($links)) { return ''; } $level_tmp = explode('-', key($links)); $level = $level_tmp[0]; $output = "<ul id="nav" class="nav">\n"; foreach ($links as $index => $link) { $output .= "<li>". l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment']) ."</li>\n"; } $output .= '</ul>';
return $output; } ?>
Which is basically a modified version of theme_menu_links in menu.inc
It works as a start, but there are a couple of issues. 1. even though my class attribute in $output is hard coded, it's still being replaced by class="active" when you're on the page. Not a disaster, i can always modify my css to do the same thing for class="active" as class="nav". 2. this is the bigger issue. It's not outputting the subitems. I'd be happy to add in the proper call in the foreach loop to either call another function that i also override or to load them directly in here if anyone can point me in the direction of what i need to call in order to load them.
--
sander-martijn mailto:sander@sander-martijn.com interface developer | architect sander@sander-martijn.com mailto:sander@sander-martijn.com www.sander-martijn.com http://www.sander-martijn.com
Thanks. I actually tried that technique first (it shows at the bottom of this email), before trying the options below, but what I found was that the primary_links menu wasn't populated with it's children which is why i started digging around these deeper parts of the system - what i was initially looking for was to find a function that I could call that would give me the full array (like what shows if you use the default menu module).
print_r output gives:
Array ( [menu-1-1-2] => Array ( [title] => Photo Gallery [href] => node/2 [attributes] => Array ( ) )
[menu-1-2-2] => Array ( [title] => Floor Plans [href] => node/5 [attributes] => Array ( ) ) ) 1
Even though Photo Gallery has a child which is listed if you load the default menu module that comes with drupal:
<ul class="menu"> <li class="expanded"><a href="/?q=photoGallery">Photo Gallery</a> <ul class="menu"> <li class="leaf"><a href="/?q=photoGallery/residential">Residential Photos</a></li> </ul> </li> <li class="leaf"><a href="/?q=floorplans">Floor Plans</a></li> </ul>
So I guess the question is - how do I get a primary link's children (eg Residential Photos) to appear in an array I can traverse?
Eric Mckenna wrote:
Forgot to to add that you will have to get intimate with the $primary_links array, but its not difficult. Throw in a print_r($links) and you have all you need.
Eric Mckenna wrote:
You can use theme_menu_tree and theme_menu_item, but you will theme every menu that passes through the menu system that way. What I like to do is do my own theme for the menu items on your page.tpl.php
<?php print theme('my_menu_themeing', $primary_links); ?>
inside your template.tpl.php function THEME_NAME_my_menu_themeing($links) { $output; .. custom html with my menu ... return $output; }
see it that works for you. Eric.
sander-martijn wrote:
Making some progress here. I've realized that to some extent what I want to do is override theme_menu_tree and theme_menu_item. That gives me some of the control I need BUT the default menu system still has extra junk I don't want (such as a Primary links header) AND I need two types of menu trees that display different things - one horizontal in the top (primary links) and one vertical down the left (current section and its children). so far i think menus are a pain in the ass in drupal. a tradeoff for the power but I think the multiple meanings that the word "menu" has in drupal just adds to the confusion of it all. What I need is really not that complicated, but it's becoming incredibly complicated fast.
sander-martijn wrote:
I want to customize my menus, but since I want it to work with the html/css/javascript code I've already written and tested I want to get the system to output the menu in html as I want it. Actually what I need is quite simple. I don't really want to try to customize someone else's module and I'd rather not build one. After some digging around I figured out that I could override the theme_menu_links method in my template.php file. Now that's exactly what I need... I got really excited but I must have some things missing/misunderstood.
what I have in the menu system under primary links: primary links
- menu item 1
- menu 1 subitem 1
- menu 1 subitem 2
- menu item 2
- menu 2 subitem 1
etc - fairly standard
What I need to output is the following:
<ul id="nav1" class="nav"> <li><a href="#">menu item 1</a> <ul> <li><a href="#">menu 1 subitem 1</a></li> <li><a href="#">menu 1 subitem 2</a></li> </ul> </li> </ul> <ul id="nav2" class="nav"> <li>menu item 2 <ul> <li><a href="#">menu 2 subitem 1</a></li> </ul> </li> </ul>
etc. - also pretty straight forward.
SO - I put in page.tpl.php the following:
<?php print theme('menu_links', $primary_links); ?>
and put in template.php the following: function tpg_menu_links($links){ if (!count($links)) { return ''; } $level_tmp = explode('-', key($links)); $level = $level_tmp[0]; $output = "<ul id="nav" class="nav">\n"; foreach ($links as $index => $link) { $output .= "<li>". l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment']) ."</li>\n"; } $output .= '</ul>';
return $output; } ?>
Which is basically a modified version of theme_menu_links in menu.inc
It works as a start, but there are a couple of issues. 1. even though my class attribute in $output is hard coded, it's still being replaced by class="active" when you're on the page. Not a disaster, i can always modify my css to do the same thing for class="active" as class="nav". 2. this is the bigger issue. It's not outputting the subitems. I'd be happy to add in the proper call in the foreach loop to either call another function that i also override or to load them directly in here if anyone can point me in the direction of what i need to call in order to load them.
--
sander-martijn mailto:sander@sander-martijn.com interface developer | architect sander@sander-martijn.com mailto:sander@sander-martijn.com www.sander-martijn.com http://www.sander-martijn.com
Heh.. sorry about that. I didn't read you email close enough. One thing that might help is that you can use menu_primary_links() , http://api.drupal.org/api/function/menu_primary_links/5, to get the children.
sander-martijn wrote:
Thanks. I actually tried that technique first (it shows at the bottom of this email), before trying the options below, but what I found was that the primary_links menu wasn't populated with it's children which is why i started digging around these deeper parts of the system - what i was initially looking for was to find a function that I could call that would give me the full array (like what shows if you use the default menu module).
print_r output gives: Array ( [menu-1-1-2] => Array ( [title] => Photo Gallery [href] => node/2 [attributes] => Array ( ) )
[menu-1-2-2] => Array ( [title] => Floor Plans [href] => node/5 [attributes] => Array ( ) )) 1 Even though Photo Gallery has a child which is listed if you load the default menu module that comes with drupal:
<ul class="menu"> <li class="expanded"><a href="/?q=photoGallery">Photo Gallery</a> <ul class="menu"> <li class="leaf"><a href="/?q=photoGallery/residential">Residential Photos</a></li> </ul> </li> <li class="leaf"><a href="/?q=floorplans">Floor Plans</a></li> </ul>
So I guess the question is - how do I get a primary link's children (eg Residential Photos) to appear in an array I can traverse?
Eric Mckenna wrote:
Forgot to to add that you will have to get intimate with the $primary_links array, but its not difficult. Throw in a print_r($links) and you have all you need.
Eric Mckenna wrote:
You can use theme_menu_tree and theme_menu_item, but you will theme every menu that passes through the menu system that way. What I like to do is do my own theme for the menu items on your page.tpl.php
<?php print theme('my_menu_themeing', $primary_links); ?>
inside your template.tpl.php function THEME_NAME_my_menu_themeing($links) { $output; .. custom html with my menu ... return $output; }
see it that works for you. Eric.
sander-martijn wrote:
Making some progress here. I've realized that to some extent what I want to do is override theme_menu_tree and theme_menu_item. That gives me some of the control I need BUT the default menu system still has extra junk I don't want (such as a Primary links header) AND I need two types of menu trees that display different things - one horizontal in the top (primary links) and one vertical down the left (current section and its children). so far i think menus are a pain in the ass in drupal. a tradeoff for the power but I think the multiple meanings that the word "menu" has in drupal just adds to the confusion of it all. What I need is really not that complicated, but it's becoming incredibly complicated fast.
sander-martijn wrote:
I want to customize my menus, but since I want it to work with the html/css/javascript code I've already written and tested I want to get the system to output the menu in html as I want it. Actually what I need is quite simple. I don't really want to try to customize someone else's module and I'd rather not build one. After some digging around I figured out that I could override the theme_menu_links method in my template.php file. Now that's exactly what I need... I got really excited but I must have some things missing/misunderstood.
what I have in the menu system under primary links: primary links
- menu item 1
- menu 1 subitem 1
- menu 1 subitem 2
- menu item 2
- menu 2 subitem 1
etc - fairly standard
What I need to output is the following:
<ul id="nav1" class="nav"> <li><a href="#">menu item 1</a> <ul> <li><a href="#">menu 1 subitem 1</a></li> <li><a href="#">menu 1 subitem 2</a></li> </ul> </li> </ul> <ul id="nav2" class="nav"> <li>menu item 2 <ul> <li><a href="#">menu 2 subitem 1</a></li> </ul> </li> </ul>
etc. - also pretty straight forward.
SO - I put in page.tpl.php the following:
<?php print theme('menu_links', $primary_links); ?>
and put in template.php the following: function tpg_menu_links($links){ if (!count($links)) { return ''; } $level_tmp = explode('-', key($links)); $level = $level_tmp[0]; $output = "<ul id="nav" class="nav">\n"; foreach ($links as $index => $link) { $output .= "<li>". l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment']) ."</li>\n"; } $output .= '</ul>';
return $output; } ?>
Which is basically a modified version of theme_menu_links in menu.inc
It works as a start, but there are a couple of issues. 1. even though my class attribute in $output is hard coded, it's still being replaced by class="active" when you're on the page. Not a disaster, i can always modify my css to do the same thing for class="active" as class="nav". 2. this is the bigger issue. It's not outputting the subitems. I'd be happy to add in the proper call in the foreach loop to either call another function that i also override or to load them directly in here if anyone can point me in the direction of what i need to call in order to load them.
--
sander-martijn mailto:sander@sander-martijn.com interface developer | architect sander@sander-martijn.com mailto:sander@sander-martijn.com www.sander-martijn.com http://www.sander-martijn.com
--
sander-martijn mailto:sander@sander-martijn.com interface developer | architect sander@sander-martijn.com mailto:sander@sander-martijn.com www.sander-martijn.com http://www.sander-martijn.com
yeah, tried that too but i'm still not understanding something. No matter what I put in that (tried a variety of options in case i was misunderstanding what the args do) I either get just the top level or I get nothing:
menu_primary_links() Array ( [menu-1-1-2] => Array ( [title] => Photo Gallery [href] => node/2 [attributes] => Array ( )
)
[menu-1-2-2] => Array ( [title] => Floor Plans [href] => node/5 [attributes] => Array ( )
)
) menu_primary_links(1) Array ( [menu-1-1-2] => Array ( [title] => Photo Gallery [href] => node/2 [attributes] => Array ( )
)
[menu-1-2-2] => Array ( [title] => Floor Plans [href] => node/5 [attributes] => Array ( )
)
) menu_primary_links(2) menu_primary_links(1,2) Array ( [menu-1-1-2] => Array ( [title] => Photo Gallery [href] => node/2 [attributes] => Array ( )
)
[menu-1-2-2] => Array ( [title] => Floor Plans [href] => node/5 [attributes] => Array ( )
)
) menu_primary_links(2,1) Array ( )
Eric Mckenna wrote:
Heh.. sorry about that. I didn't read you email close enough. One thing that might help is that you can use menu_primary_links() , http://api.drupal.org/api/function/menu_primary_links/5, to get the children.
trimming thread, it's getting long
one more note - the navigation i'm working on at the moment will not change for the site (and i'm not worried about reusability at the moment), so i'm perfectly fine with putting in a series of calls such as this if it works (purposely not written in code): * give me menu from node 2 and children * give me menu from node 5 and children
etc. totally unreusable but will work for this case and when I have more time to get a deeper understanding of how all this is working i'd learn to do it right. so whether i can get a nested array of the primary links and their children as i was trying to get below or simply get a series of arrays of the children of photo gallery, the children of floor plans etc doesn't matter to me at the moment - i can work with either.
sander-martijn wrote:
yeah, tried that too but i'm still not understanding something. No matter what I put in that (tried a variety of options in case i was misunderstanding what the args do) I either get just the top level or I get nothing:
menu_primary_links() Array ( [menu-1-1-2] => Array ( [title] => Photo Gallery [href] => node/2 [attributes] => Array ( )
) [menu-1-2-2] => Array ( [title] => Floor Plans [href] => node/5 [attributes] => Array ( ) )) menu_primary_links(1) Array ( [menu-1-1-2] => Array ( [title] => Photo Gallery [href] => node/2 [attributes] => Array ( )
) [menu-1-2-2] => Array ( [title] => Floor Plans [href] => node/5 [attributes] => Array ( ) )) menu_primary_links(2) menu_primary_links(1,2) Array ( [menu-1-1-2] => Array ( [title] => Photo Gallery [href] => node/2 [attributes] => Array ( )
) [menu-1-2-2] => Array ( [title] => Floor Plans [href] => node/5 [attributes] => Array ( ) )) menu_primary_links(2,1) Array ( )
Eric Mckenna wrote:
Heh.. sorry about that. I didn't read you email close enough. One thing that might help is that you can use menu_primary_links() , http://api.drupal.org/api/function/menu_primary_links/5, to get the children.
trimming thread, it's getting long
You might consider abandoning the primary links construct and just create a custom region for your theme and put the primary links block in that region. If the "menu-block" gives you what you wan't that might work. You then disable primary and secondary links in the menu.
That being said. It sounds like your problems are that your javascript is doing a a lot of DOM walking specific stuff (otherwise why would extra divs be a problem?). Is that accurate? This is part of what JQUERY was written for. In JQUERY you can bind to on-click events using typical CSS selectors. That rocks for this kind of work (even if I don't do a ton of it).
I realize that you have some already tested code. But if it's highly specified to the organization of the document it could cause you a lot of problems in the long run, so I thought you'd want to know about JQuery.
Hope some of this helps anyway.
Dave
________________________________
From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of sander-martijn Sent: Thursday, August 16, 2007 5:15 PM To: support@drupal.org Subject: Re: [support] Menu question
Making some progress here. I've realized that to some extent what I want to do is override theme_menu_tree and theme_menu_item. That gives me some of the control I need BUT the default menu system still has extra junk I don't want (such as a Primary links header) AND I need two types of menu trees that display different things - one horizontal in the top (primary links) and one vertical down the left (current section and its children).
so far i think menus are a pain in the ass in drupal. a tradeoff for the power but I think the multiple meanings that the word "menu" has in drupal just adds to the confusion of it all. What I need is really not that complicated, but it's becoming incredibly complicated fast.
sander-martijn wrote:
I want to customize my menus, but since I want it to work with the html/css/javascript code I've already written and tested I want to get the system to output the menu in html as I want it. Actually what I need is quite simple. I don't really want to try to customize someone else's module and I'd rather not build one. After some digging around I figured out that I could override the theme_menu_links method in my template.php file. Now that's exactly what I need... I got really excited but I must have some things missing/misunderstood. what I have in the menu system under primary links: primary links - menu item 1 - menu 1 subitem 1 - menu 1 subitem 2 - menu item 2 - menu 2 subitem 1 etc - fairly standard What I need to output is the following: <ul id="nav1" class="nav"> <li><a href="#">menu item 1</a> <ul> <li><a href="#">menu 1 subitem 1</a></li> <li><a href="#">menu 1 subitem 2</a></li> </ul> </li> </ul> <ul id="nav2" class="nav"> <li>menu item 2 <ul> <li><a href="#">menu 2 subitem 1</a></li> </ul> </li> </ul> etc. - also pretty straight forward. SO - I put in page.tpl.php the following: <?php print theme('menu_links', $primary_links); ?> and put in template.php the following: function tpg_menu_links($links){ if (!count($links)) { return ''; } $level_tmp = explode('-', key($links)); $level = $level_tmp[0]; $output = "<ul id="nav" class="nav">\n"; foreach ($links as $index => $link) { $output .= "<li>". l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment']) ."</li>\n"; } $output .= '</ul>'; return $output; } ?> Which is basically a modified version of theme_menu_links in menu.inc It works as a start, but there are a couple of issues. 1. even though my class attribute in $output is hard coded, it's still being replaced by class="active" when you're on the page. Not a
disaster, i can always modify my css to do the same thing for class="active" as class="nav". 2. this is the bigger issue. It's not outputting the subitems. I'd be happy to add in the proper call in the foreach loop to either call another function that i also override or to load them directly in here if anyone can point me in the direction of what i need to call in order to load them.
They're actually css menus only. The thing is, i'm quite certain I can build what i need to with drupal i'm just having trouble with the documentation. I won't rant about it, i don't really have the time and i'm sure you don't either.
The main things I'm dealing with is 1: very specific (but not that unusual) requirements of what menus should do on the site 2: a site that got mostly built already in a commercial cms that can't handle even the most basic requirements - I'm in damage control mode now trying to salvage a project by bringing it to drupal.
In the meantime I used the nice_menus module for the top nav which pretty much can do what I need it to do in the short term, but may cause problems once there is a third level which shouldn't show in the top nav. Now I'm trying to get the left nav to display how that should. I'm basically doing a lot of print_r in my templates right now so I can get an idea of what's going on.
given this structure: - home - top level links - 2nd level - 3rd level
top nav: show on all pages, display top level links and their 2nd level links (through css dropdowns) left nav: show on top level links and below, list top level link and 2nd level links when on top level, list top level link, 2nd level links and current 2nd level link's children indented when on 2nd or 3rd level
So I don't need javascript or JQuery for this - if I can get arrays containing these elements then I can use template override functions, custom php code or whatever else to get what I need. I'd rather not write a module for this but if that's the only option I'll go that route.
thanks .sander
Metzler, David wrote:
You might consider abandoning the primary links construct and just create a custom region for your theme and put the primary links block in that region. If the "menu-block" gives you what you wan't that might work. You then disable primary and secondary links in the menu.
That being said. It sounds like your problems are that your javascript is doing a a lot of DOM walking specific stuff (otherwise why would extra divs be a problem?). Is that accurate? This is part of what JQUERY was written for. In JQUERY you can bind to on-click events using typical CSS selectors. That rocks for this kind of work (even if I don't do a ton of it).
I realize that you have some already tested code. But if it's highly specified to the organization of the document it could cause you a lot of problems in the long run, so I thought you'd want to know about JQuery.
Hope some of this helps anyway.
Dave
*From:* support-bounces@drupal.org [mailto:support-bounces@drupal.org] *On Behalf Of *sander-martijn *Sent:* Thursday, August 16, 2007 5:15 PM *To:* support@drupal.org *Subject:* Re: [support] Menu question
Making some progress here. I've realized that to some extent what I want to do is override theme_menu_tree and theme_menu_item. That gives me some of the control I need BUT the default menu system still has extra junk I don't want (such as a Primary links header) AND I need two types of menu trees that display different things - one horizontal in the top (primary links) and one vertical down the left (current section and its children).
so far i think menus are a pain in the ass in drupal. a tradeoff for the power but I think the multiple meanings that the word "menu" has in drupal just adds to the confusion of it all. What I need is really not that complicated, but it's becoming incredibly complicated fast.
sander-martijn wrote:
I want to customize my menus, but since I want it to work with the html/css/javascript code I've already written and tested I want to get the system to output the menu in html as I want it. Actually what I need is quite simple. I don't really want to try to customize someone else's module and I'd rather not build one. After some digging around I figured out that I could override the theme_menu_links method in my template.php file. Now that's exactly what I need... I got really excited but I must have some things missing/misunderstood.
what I have in the menu system under primary links: primary links
- menu item 1
- menu 1 subitem 1
- menu 1 subitem 2
- menu item 2
- menu 2 subitem 1
etc - fairly standard
What I need to output is the following:
<ul id="nav1" class="nav"> <li><a href="#">menu item 1</a> <ul> <li><a href="#">menu 1 subitem 1</a></li> <li><a href="#">menu 1 subitem 2</a></li> </ul> </li> </ul> <ul id="nav2" class="nav"> <li>menu item 2 <ul> <li><a href="#">menu 2 subitem 1</a></li> </ul> </li> </ul>
etc. - also pretty straight forward.
SO - I put in page.tpl.php the following:
<?php print theme('menu_links', $primary_links); ?>
and put in template.php the following: function tpg_menu_links($links){ if (!count($links)) { return ''; } $level_tmp = explode('-', key($links)); $level = $level_tmp[0]; $output = "<ul id="nav" class="nav">\n"; foreach ($links as $index => $link) { $output .= "<li>". l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment']) ."</li>\n"; } $output .= '</ul>';
return $output; } ?>
Which is basically a modified version of theme_menu_links in menu.inc
It works as a start, but there are a couple of issues.
- even though my class attribute in $output is hard coded, it's still
being replaced by class="active" when you're on the page. Not a disaster, i can always modify my css to do the same thing for class="active" as class="nav". 2. this is the bigger issue. It's not outputting the subitems. I'd be happy to add in the proper call in the foreach loop to either call another function that i also override or to load them directly in here if anyone can point me in the direction of what i need to call in order to load them.
--
sander-martijn mailto:sander@sander-martijn.com interface developer | architect sander@sander-martijn.com mailto:sander@sander-martijn.com www.sander-martijn.com http://www.sander-martijn.com
here's the solution I found for the left nav requirements:
<?php $trail = _menu_get_active_trail(); $mid = $trail[1]; $output .= theme('menu_item', $mid); $output.= theme('menu_tree',$mid); print('<div id="menubox"><ul class="menu">'); print $output; print('</ul></div>'); ?>
I'm QUITE certain there's a more elegant way of accomplishing this, but until I find out what it is this at least works.
To test it I had to add in my first 3rd level page and was right about nice_menus showing that, so I have to either find a way to stop that or find another solution.
sander-martijn wrote:
They're actually css menus only. The thing is, i'm quite certain I can build what i need to with drupal i'm just having trouble with the documentation. I won't rant about it, i don't really have the time and i'm sure you don't either.
The main things I'm dealing with is 1: very specific (but not that unusual) requirements of what menus should do on the site 2: a site that got mostly built already in a commercial cms that can't handle even the most basic requirements - I'm in damage control mode now trying to salvage a project by bringing it to drupal.
In the meantime I used the nice_menus module for the top nav which pretty much can do what I need it to do in the short term, but may cause problems once there is a third level which shouldn't show in the top nav. Now I'm trying to get the left nav to display how that should. I'm basically doing a lot of print_r in my templates right now so I can get an idea of what's going on.
given this structure:
- home
- top level links
- 2nd level
- 3rd level
top nav: show on all pages, display top level links and their 2nd level links (through css dropdowns) left nav: show on top level links and below, list top level link and 2nd level links when on top level, list top level link, 2nd level links and current 2nd level link's children indented when on 2nd or 3rd level
So I don't need javascript or JQuery for this - if I can get arrays containing these elements then I can use template override functions, custom php code or whatever else to get what I need. I'd rather not write a module for this but if that's the only option I'll go that route.
thanks .sander
Metzler, David wrote:
You might consider abandoning the primary links construct and just create a custom region for your theme and put the primary links block in that region. If the "menu-block" gives you what you wan't that might work. You then disable primary and secondary links in the menu.
That being said. It sounds like your problems are that your javascript is doing a a lot of DOM walking specific stuff (otherwise why would extra divs be a problem?). Is that accurate? This is part of what JQUERY was written for. In JQUERY you can bind to on-click events using typical CSS selectors. That rocks for this kind of work (even if I don't do a ton of it).
I realize that you have some already tested code. But if it's highly specified to the organization of the document it could cause you a lot of problems in the long run, so I thought you'd want to know about JQuery.
Hope some of this helps anyway.
Dave
*From:* support-bounces@drupal.org [mailto:support-bounces@drupal.org] *On Behalf Of *sander-martijn *Sent:* Thursday, August 16, 2007 5:15 PM *To:* support@drupal.org *Subject:* Re: [support] Menu question
Making some progress here. I've realized that to some extent what I want to do is override theme_menu_tree and theme_menu_item. That gives me some of the control I need BUT the default menu system still has extra junk I don't want (such as a Primary links header) AND I need two types of menu trees that display different things - one horizontal in the top (primary links) and one vertical down the left (current section and its children).
so far i think menus are a pain in the ass in drupal. a tradeoff for the power but I think the multiple meanings that the word "menu" has in drupal just adds to the confusion of it all. What I need is really not that complicated, but it's becoming incredibly complicated fast.
sander-martijn wrote:
I want to customize my menus, but since I want it to work with the html/css/javascript code I've already written and tested I want to get the system to output the menu in html as I want it. Actually what I need is quite simple. I don't really want to try to customize someone else's module and I'd rather not build one. After some digging around I figured out that I could override the theme_menu_links method in my template.php file. Now that's exactly what I need... I got really excited but I must have some things missing/misunderstood.
what I have in the menu system under primary links: primary links
- menu item 1
- menu 1 subitem 1
- menu 1 subitem 2
- menu item 2
- menu 2 subitem 1
etc - fairly standard
What I need to output is the following:
<ul id="nav1" class="nav"> <li><a href="#">menu item 1</a> <ul> <li><a href="#">menu 1 subitem 1</a></li> <li><a href="#">menu 1 subitem 2</a></li> </ul> </li> </ul> <ul id="nav2" class="nav"> <li>menu item 2 <ul> <li><a href="#">menu 2 subitem 1</a></li> </ul> </li> </ul>
etc. - also pretty straight forward.
SO - I put in page.tpl.php the following:
<?php print theme('menu_links', $primary_links); ?>
and put in template.php the following: function tpg_menu_links($links){ if (!count($links)) { return ''; } $level_tmp = explode('-', key($links)); $level = $level_tmp[0]; $output = "<ul id="nav" class="nav">\n"; foreach ($links as $index => $link) { $output .= "<li>". l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment']) ."</li>\n"; } $output .= '</ul>';
return $output; } ?>
Which is basically a modified version of theme_menu_links in menu.inc
It works as a start, but there are a couple of issues.
- even though my class attribute in $output is hard coded, it's still
being replaced by class="active" when you're on the page. Not a disaster, i can always modify my css to do the same thing for class="active" as class="nav". 2. this is the bigger issue. It's not outputting the subitems. I'd be happy to add in the proper call in the foreach loop to either call another function that i also override or to load them directly in here if anyone can point me in the direction of what i need to call in order to load them.
--
sander-martijn mailto:sander@sander-martijn.com interface developer | architect sander@sander-martijn.com mailto:sander@sander-martijn.com www.sander-martijn.com http://www.sander-martijn.com
--
sander-martijn mailto:sander@sander-martijn.com interface developer | architect sander@sander-martijn.com mailto:sander@sander-martijn.com www.sander-martijn.com http://www.sander-martijn.com