Menu

Learn and show support?

Why use the Context module to add blocks to regions

You probably heard of this module called Context in Drupal. Well, it’s been there since Drupal 6. This is one of those really simple but powerful modules that make it easy for you to have certain things happen or display according to a context you define. The context can be either the path your site is currently on, the node type currently rendered etc.

There is one interesting aspect that I would like to mention in this respect.

The Drupal block module provides the default way of assigning blocks to regions. To do this you go to Structure – Blocks administration menu where you can also specify what roles can see the block, what content type they should appear [or not] in, or even on what paths. That’s all good and well, but what if you want to have block A appear as the second block on a front page region afterblock B but first on another page, beforeblock B, what do you do? You use Context!

With Context you can set multiple contexts for various purposes. For our case let’s say one for the front page and another for node/6 (for these examples you would use Path as the Context condition). As reactions to the conditions of both those contexts, you can assign your blocks to your regions in any order you want. And this way you can have block B as first and block A as second on the front page, and block A as first and block B as second on another page (node/6 for instance) or other pages, nodes, paths, content types, etc.