I'm trying to figure out how to accomplish the following, any help would be really apprecaited (or someone saying "that's not possible" so I stop trying :)

On every site I build I have a sitewide context which includes things like main navigation menu, footer information, etc. Stuff that should show on every page. I then want to set a 'fallback' or default context to use whenever there's no other contexts active except for the sitewide.

Now, I know I can do a default context by putting in a context condition of ~* (which means, not any other contexts are active). The problem is, the sitewide context is ALWAYS active, so that will never return true.

So, how can I put in a condition that says "there are no context active besides the sitewide context"? Or, to put it another way: "my sitewide context is the only active context".

Doing this will allow me to have a default context that is in effect when no other 'real' (ie. not sitewide) contexts are active.

Thoughts on accomplishing this?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Maciej Lukianski’s picture

+1 I am just looking for the same thing.

So far I acomplished this by placing sitewide blocks in regions using the default block system. The deafault context than works providing default blocks for all situations where no specific context is present.
This way I cover all 3 secenarios:

1. I have sitewide blocks like Login or Navigation present all the time no matter what
2. I have blocks from custom contexts for specific areas - ie users comments blocks on user pages, latest articles blocks in news area, etc.
3. If by accident or design I do not define a context for an area of the site - say groups or some views pages, I am not left with just Login/Navi, because a get a bunch of blocks from the default context that fill the sidebar also engaging the user.

In my opinion, the default context should ignore the sitewide context by default. This way the 3 step scenario could be achieved solely via context. Or does it ignore it somehow, and I just don't know how to turn it on?

Maciej Lukianski’s picture

Ok, never mind.

If you set a sitewide context and default context with different attributes, the default context presents itself along the sitewide context.

The default is default for the attribute. If you have contexts with other attributes, they will show alongside the default one.

fearlsgroove’s picture

Title: Setting a Default Context, Ignoring Sitewide » Default context condition that applies when no other non-sitewide context is active
Version: 6.x-3.x-dev » 7.x-3.x-dev
FileSize
3.1 KB

I've had the same requirement on enough sites that I built a condition that deals with this. It works similar to sitewide, except that it will only be active if no other context with a condition other than sitewide or default is active. This allows precisely the scenario outlined by the OP: A sitewide context supplying things like footer menus, plus a "default" context that provides blocks if no other context does so.

fearlsgroove’s picture

Status: Active » Needs review

nr

xmacinfo’s picture

Is there a way to achieve this (#3) in template.php until it's available in the Context module?

Or in a custom module?

fearlsgroove’s picture

Slight update changes the behavior such that the default context applies if:
1. there are no other contexts active OR
2. Any other active contexts have either a default condition or a sitewide condition.

Previously if other active contexts had any condition other than default or sitewide, they would prevent the default context from applying, which I found too restricting.

fearlsgroove’s picture

Here's a reroll of #6 including the new file, which was missing. I'm surprised this hasn't gotten any more traction - I use this feature on just about every site I build ...

ttkaminski’s picture

#7 patch works well. I am also surprised that this issue hasn't gotten much attention. I just started using Context for the first time, and I immediately ran into this issue. Before finding your patch, I implemented a fix to the core Context Condition by accepting full blown regular expressions in the patterns. My site wide context is named global and so my regex pattern in the default context was:

~#^(?!global).*$#i

Basically, the above pattern is saying to disable the current (default) context for any other context while ignoring global. The small patch enables regular expressions, and it's detected for any line that starts with # (PCRE delimiter). I chose this instead of forward slash because it's probably less likely a # would be in a path or context name. ~ (not operator) is still supported.

The downside to this approach is that you need to know regular expressions. The upside is that you don't need to write a plugin for every special case.

micromegas’s picture

Component: Documentation » Code
Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

#7 works as advertised; RTBC.

fearlsgroove’s picture

Whitespace only reroll .. leaving RTBC

  • colan committed efb3cc5 on 7.x-3.x authored by fearlsgroove
    Issue #1018834 by fearlsgroove, ttkaminski | Rob_Feature: Add a no-...
colan’s picture

Version: 7.x-3.x-dev » 7.x-3.3
Status: Reviewed & tested by the community » Fixed

Thanks!

Status: Fixed » Closed (fixed)

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