Profile picture for user admin
Daniel Sipos
23 Nov 2012

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 after block B but first on another page, before block 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.

And don't forget about the plethora of modules that extend the basic block functionality.

Check it out, hope this helps.

NB: Context requires the Chaos tool suite (ctools) to be installed on your website. Also, if you can learn how to add new regions to your page template (page.tpl.php) or call them even in your node template (node.tpl.php).

Profile picture for user admin

Daniel Sipos

CEO @ Web Omelette

Danny founded WEBOMELETTE in 2012 as a passion project, mostly writing about Drupal problems he faced day to day, as well as about new technologies and things that he thought other developers would find useful. Now he now manages a team of developers and designers, delivering quality products that make businesses successful.

Contact us

Add new comment