Highlighted tabs, primary links, and bread crumbs
I'm working on a new site for which I am using primary links (i.e. menu items) as tabs across the top of each page to describe different areas. It would be nice if I could visually segregate content into the different areas by highlighting the correct tab. i have several thousand pieces of content, and the number is growing. If I simply defined menu items for each node, I expect performance would diminish as the size of $menu increased. Other people have tried to accomplish this highlighting trick using hacks and kludges (e.g. http://drupal.org/node/46020). I have done the same until now. But for some reason, PHP in page.tpl.php does not have access to the current page's query string or bread crumbs. This seems to be a recent change in HEAD. So, to determine which tab to activate, I am comparing in page.tpl.php the supplied bread crumb links with the supplied primary links. When there is a match, I activate the primary link so the tab looks highlighted. But how can I define arbitrary bread crumbs for a large number of nodes? Is there a better way to do this? Has anyone else done this? Nic
As for theming : the way the arrays $primary_links and $secondary_links are built can help you on that. While the values of the array contains the html for the links, the _keys_ give you information on which item is "active". That is much better than comparing breadcrumbs pieces to primary links. You still have to attach your content one way or another to the menu hierarchy. The 'menu_set_location' in menu api has precisely that purpose. But being an api function, using it requires, well, coding... Meaning, if you are a coder, it should be rather simple to build your own classification code in a small dedicated module and attach your content to the right menu trail 'on the fly' on each page display (in hook_menu) If you're not, or if you want full fledged features, then category.module is your friend. Yves Nic Ivy a ecrit le 28/03/2006 22:29:
I'm working on a new site for which I am using primary links (i.e. menu items) as tabs across the top of each page to describe different areas. It would be nice if I could visually segregate content into the different areas by highlighting the correct tab.
i have several thousand pieces of content, and the number is growing. If I simply defined menu items for each node, I expect performance would diminish as the size of $menu increased.
Other people have tried to accomplish this highlighting trick using hacks and kludges (e.g. http://drupal.org/node/46020). I have done the same until now. But for some reason, PHP in page.tpl.php does not have access to the current page's query string or bread crumbs. This seems to be a recent change in HEAD.
So, to determine which tab to activate, I am comparing in page.tpl.php the supplied bread crumb links with the supplied primary links. When there is a match, I activate the primary link so the tab looks highlighted.
But how can I define arbitrary bread crumbs for a large number of nodes?
Is there a better way to do this? Has anyone else done this?
Nic
I got it to work. Here's how: Taking Yves' suggestion, I created a module whose sole purpose is to mangle the global $_menu during the 'view' phase of hook_nodeapi(). This code uses a lookup table in order to adjust the parent-child relationships between the current node and the desired primary link. In this way, the desired primary link (i.e. menu item) becomes part of the active trail. In page.tpl.php, the key for the $primary_links indicates which menu items are in the active trail. So after a quick strpos() check, the proper primary link is highlighted. So I got what I need out of this and do not intend to publish the module. It is very rough around the edges. If someone else wants to take this code and polish the UI, I will give you what I have. Write to me off-list. Nic On Mar 28, 2006, at 3:26 PM, Yves CHEDEMOIS wrote:
As for theming : the way the arrays $primary_links and $secondary_links are built can help you on that. While the values of the array contains the html for the links, the _keys_ give you information on which item is "active". That is much better than comparing breadcrumbs pieces to primary links.
You still have to attach your content one way or another to the menu hierarchy. The 'menu_set_location' in menu api has precisely that purpose. But being an api function, using it requires, well, coding...
Meaning, if you are a coder, it should be rather simple to build your own classification code in a small dedicated module and attach your content to the right menu trail 'on the fly' on each page display (in hook_menu)
If you're not, or if you want full fledged features, then category.module is your friend.
Yves
Regarding the lookup table, it only associates content types with primary links. So the size of the table is small. N On Mar 29, 2006, at 9:39 AM, Nic Ivy wrote:
This code uses a lookup table in order to adjust the parent-child relationships between the current node and the desired primary link.
I wrote some custom theme functions for the Mollio theme that adds "active" classes to parent list items if one of the children is already marked active. They're in template.php if you try downloading the CVS version of the mollio theme.
participants (3)
-
Nic Ivy -
Rowan Kerr -
Yves CHEDEMOIS