i can't get it to work to set a menu active, when a certain condition is given. the problem is, that i don't know how to handle this advice "To use this feature, you must use theme_context_links() to theme your links".
where and how do i manage this?
thanks in advance

Comments

yhahn’s picture

Assigned: Unassigned » yhahn
Status: Active » Fixed

Sorry, this helptext is very out of date. I've updated it with this commit http://drupal.org/cvs?commit=225056

When using the active menu reaction, the links you've selected will get an active class in the $primary_links or $secondary_links of your page.tpl.php. All you need to do after that is add the appropriate CSS in your theme.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ranavaibhav’s picture

Version: 6.x-1.0-alpha4 » 6.x-2.0-beta2
Component: Documentation » User interface
Status: Closed (fixed) » Active

Hello,

I'm sorry if I'm not suppose to re-open issue, but i did because I'm facing similar problem.

I have set one of my primary link menu to be activated when I'm in a context section (i have set context for all story pages)
When ever I'm viewing a story page i see the context is being activated in the context devel block however the menu item is not being activated.
I tried changing the active menu setting to the secondary menu item as well as my custom menu item, but no luck.
I tried different theme to make sure the problem is not with the theme I'm using (tapstry)
I also tried the committed version of "context.core.inc" file from the above link (comment #1)

Please advise what else could be an issue? Thanks.

tanc’s picture

Version: 6.x-2.0-beta2 » 6.x-2.0-beta4

It doesn't appear to do anything for me either. Looking through the code, I'm struggling to find anywhere that adds an active class to a menu item.

tanc’s picture

Ok, I worked out that there is a preprocess page function which should set the active link in the function context_preprocess_page(). I had my $primary_links variable turned off in the theme settings so it wasn't being populated. Once I'd switched it on it still wasn't altering it in context_menu_set_active(). The $links variable gets populated with the primary links array but only the top level of the menu system. I don't know if this is by design as I don't know a lot about the internal workings of Drupal's menu system.

Aside from all this, my main problem is that I'm using 3rd party modules to style my links. I have Nice Menus displaying a horizontal drop down menu and Menu Block displaying a sidebar block with the current Primary Menu Links' children. I would need to add active classes to both these blocks for this feature to work. Any ideas how this can be achieved?

rossymole’s picture

Having the same issue, using the Context Devel block and setting other context functions I believe I have context configured correctly, yet no active menu state. Ideas?

snufkin’s picture

The primary links will not set active if you use them through the primary links block. The workflow for rendering blocks doesn't allow context to intervene and change the menu structure as it does with the page preprocess.

q0rban’s picture

Re: #5

I used some jquery to get nice_menus to work with active and hovered items, if you're interested:

$(function () {
  // Make the menu parent anchor active if a child element is active.
  $('ul.nice-menu li.menuparent li a.active').parents('li.menuparent').children('a').addClass('active');
  // Add a hover class to the menu parent anchor if hovering the child menu.
  $('ul.nice-menu ul').hover(
    function() {
      $(this).parents('li.menuparent').children('a').addClass('hover');
    },
    function() {
      $(this).parents('li.menuparent').children('a').removeClass('hover');
    }
  );
});

Nice thing about this is it also adds a hover class to the parent item when you are hovering over a child item. Hope that's helpful...

q0rban’s picture

To get this working with nice_menus, you can also (in theme foo, e.g.) override the theme_nice_menu_build function like so:

/**
 * Helper function that builds the nested lists of a nice menu.
 *
 * @param $menu
 *   Menu array from which to build the nested lists.
 */
function foo_nice_menu_build($menu) {
  // Retrieve original path so we can repair it after our hack.
  $original_path = $_GET['q'];

  if (function_exists('context_active_values')) {
    // Retrieve the first active menu path found.
    $active_paths = context_active_values('menu');
    if (!empty($active_paths)) {
      $path = current($active_paths);
      if (menu_get_item($path)) {
        menu_set_active_item($path);
      }
    }
  }

  $output = theme_nice_menu_build($menu);

  menu_set_active_item($original_path);

  return $output;
}
monteco’s picture

I was having the same problem as tanc with my Nice Menus, and q0rban's nice_menu_build function worked for me. Thanks!

Steven Jones’s picture

Title: active menu in primary links » Document the menu links issue
Component: User interface » Documentation
Assigned: yhahn » Unassigned
Category: support » feature
Issue tags: +context-2.x-rc-blocker

I think that we just need some documentation about menu links and setting them to be active.

Steven Jones’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)
Issue tags: -context-2.x-rc-blocker

Automatically closed -- issue fixed for 2 weeks with no activity.