Let's say I have a primary menu like this:

  • Section 1
    • Page 1
    • View page
    • Page 23
  • Section 2
    • Page 3
    • Page 5
    • Page 9
      • Third level, page 35
      • Page 67
      • View Page
  • Section 3

I need the ability to trigger a context based on my menu path. For instance if I was on page 9, I should be in context "section 2." Currently, there seems to be no way to do this without custom code or adding specific node ids.

So I envision the menu integration happening like nodequeue or views, pick a menu, and then pick a parent.

Or can I do that now? I'll admit that I haven't tried version 2, since it's code is not recommended on the project page. Thanks for the help everyone!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joshmiller’s picture

Read through some of the other issues and found a common theme: When asked for a specific context trigger, they are often met with "use paths."

I'm going to use pathauto and node hierarchy to generate hierarchical paths automatically.

What's scary about this? Paths are DESIGNED to be flexible and change.

Possible simple solutions:

  • Context based on relationship to nid within menu
  • Context based on taxonomy id
  • Tell josh to actually make a patch
  • Use paths and shut-the-f-up

Just sayin' ...

Pasqualle’s picture

use paths

joshmiller’s picture

Priority: Normal » Minor
Status: Active » Postponed

If my contexts are based on paths, then zen does everything I need with the body classes that read "section-parentpath"

It's sad that I can't set context based on where I am in a menu or using taxonomy terms. Seems like this would be a very powerful combination.

Here's the reason I can't use context: I'm using ONE content type (page) that has MANY contexts. Outside of paths or nodequeue, there is no way to determine context. It seems like context solves the big problems of organizing lots of different content into smart groups, but it leaves behind the ability to organize similar content into smart groups.

Hopefully this feature request helps the developers take the next step. Not trying to nag.

joshmiller’s picture

Title: Context based on active trail » Context based on active trail (menu) and/or taxonomy

Clarifying the title for others to find...

yhahn’s picture

Assigned: Unassigned » yhahn
Status: Postponed » Active

Hi Josh,

To update you -- you're right that it's not possible to do this currently through the context UI. It should be fairly straightforward to write a menu location context condition to handle this.

If I understand correctly what you need is:

A context condition that sets the context when any of the selected menu items are in the active trail. (Widget would be a menu tree with checkboxes or multiselect?)

Re: taxonomy, there is a patch in the queue that I have regretfully not reviewed yet: http://drupal.org/node/343110. Feel free to try it out and let me know how it works out for you.

joshmiller’s picture

Absolutely what I need: "A context condition that sets the context when any of the selected menu items are in the active trail." This would solve part of my problem, the other part seems to be met by the patch in the other issue!

Thanks! I think context makes blocks make sense and am delighted that this is on the roadmap.

Josh

yhahn’s picture

I've committed a menu trail based context condition to DRUPAL-6--2. I'd love to get your testing/feedback before the next release.

http://drupal.org/cvs?commit=216554

Damien Tournoud’s picture

Nice patch. That was the only feature I was missing before actually using context ;)

link_path is generally not available in the menu trail, because the menu item is not always loaded. This is for example the case for menu links created from placeholder-based menu routers.

We have you use $item['href'] for this, patch attached.

yhahn’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

markabur’s picture

does this feature actually work?

i have the same situation as the OP but the context only gets set if i'm actually on the page that i based the context condition on -- if i'm on one if its children then the context does not get set. iow if i base the context condition on "section 2" then if i'm on "page 9" or "page 67" then the context is not set, even though the "section 2" menu item does in fact get the active-trail class when the page is rendered. the only way to get the context to be triggered on the child pages is to add them in to the condition as well. which means that the context definitions need to be updated every time my client adds a page to the site..

so, drupal somehow is correctly figuring out what the active trail is, but context module is apparently not using the same criteria. i've dug in a bit and found that menu_get_active_trail() only returns <front> and the current node, rather than the actual active-trail menu items, so i'm curious why anyone thought this patch solved the problem described by the OP.

petebarnett’s picture

markabur,

I'm having exactly the same problem. Context is only set when you are viewing the page itself... Anyone managed to get round this? I'll have a look and let you know what I find.

Thanks,
Peter

petebarnett’s picture

Ok i've worked out what the problem is...

menu_get_active_trail() only works on the currently active menu, which by default is "navigation".
If your page isn't in this menu, then the trail will just be a default of <front> and the current node.

If I call menu_set_active_menu_name() with my custom menu, the active trail is then returned correctly, and everything else works correctly.

The active menu influences more than just Context conditions though, and I'm wondering if some other solution exists for setting this?
There is a module that does this for breadcrumbs (http://drupal.org/project/menu_breadcrumb), and I've temporarily hacked context.core.inc to use the same method to get the menu that the current page belongs to.

This could be a solution, or maybe the user could select the menu to work with in the context UI?

Peter

Damien Tournoud’s picture

@peterbarnett: I see no reason why menu_breadcrumb doesn't set the active trail of the page instead of just the breadcrumb (it really seems dumb). Please open a bug report against menu_breadcrumb to do that, and it will magically make the active trail context work with all the menus.

(It's just not Context job to define what the active trail is.)

petebarnett’s picture

Hi Damien,

It just calls menu_set_active_menu_name(), which does make the active trail context work, but I guess not everyone is using the menu_breadcrumb module, and it's not a dependency of Context.

I actually ended up implementing a tiny (3 line) module with a hook_init() implementation that does exactly what menu_breadcrumb does on all pages.

I guess context allows the user to select any menu item as a trigger for the active trail condition, but in reality, only menu items from "navigation" are normally going to work (unless you're on the selected page itself).

I agree that it's not necessarily context's job to define what the active menu is, but there's definitely something missing in how the complete setup works.

Peter

markabur’s picture

i've been using menu_breadcrumb simply to get around the menu_get_active_trail() problem and it works fine... though i'm going to switch to using hook_init() as i have a custom module anyway, and don't need menu_breadcrumb for anything else.

haggins’s picture

Version: 6.x-2.0-beta1 » 6.x-2.0-beta7
Category: feature » support
Status: Closed (fixed) » Active

edit: wrong usage

haggins’s picture

Status: Active » Closed (fixed)