Drupal Context and Zen Theme

For a private project using Drupal, i tried if I can be efficient, after the not-so-awesome experience of using Drupal in a big project (more on that some other time). So far, progress for this small size project is very good. In this post, I want to share how to use the context module to change the page appearance based on the menu navigation, and how to make the Zen theme cooperate with the context module.

One requirement was to have a different footer image based on the current menu area. Thanks to the context module, this is very easy. I created normal blocks for each footer image, that just show the right image. I do not set any of the visibility options in the block creation dialog, nor do i put the block into any of the regions. In Site Building > Context, i created a context with condition "Menu" for each main menu entry. The reaction is of type "Block", and I choose the right block to show the correct footer image. Some background on the context module can be found in this Blog post from lullabot.

So far pretty straightforward. Now of course there are some pages that are not in the main menu, or maybe you have just some of the menu points being special cases. There is a very simple condition to match everything that has no context, which I use to show a default footer if there is no other footer. I think a hint should be added to the explanatory text of the corresponding condition. Instead of setting a menu condition, you just create a "Context" condition. As filter for the context, you can put ~*. The * matches any context, the ~ inverts the result, thus the context triggers whenever there is no other context active for this page. The reaction for this rule is to show the default image block.

Note that if you use other contexts for different things than the footer images, you should use a naming scheme for the context id's. If you put a "footer_" in front of each context, the condition for having no footer set would become ~foooter_*. Otherwise with ~* you might get no footer if there is no footer but some other context active.

I use the Zen theme as base for theming. It is a very clean design to start with and provides excellent element class names to control appearance with css classes. Unfortunately, Zen and context both overwrite the theme_block hook to control visibility of blocks. For some reason, Zen wins this conflict and all the nice context rules just get lost. Luckily there is a patch for Zen that makes Zen trigger other theme_block hooks. After applying this patch to Zen 6.x-2.0, I have Zen and context coexist nicely. If i read the issue tracker correctly, this patch will be included in the next version of Zen.