Using Context Module to Set Body Classes

The Context module is a great way to get a site's unwieldy block configuration page under control. It allows you to display individual blocks only when a certain "context" is available.

For example, a context may be set when a particular view is displayed. When that happens, you can use the Context module to display certain blocks alongside the view. If you find yourself writing block visibility code over-and-over again, the context module will save you time and headaches.

One of the other features of the context module is that is lets you add a CSS class to the body tag of a page when a certain context is met. This is a big advantage when you have to theme a page element in particular way only when a particular context is met.

You can find this option on the "edit context" page, in the "theme variables" section. Simply add the class names you want to include in the "section class" text field. You can also override the page title and subtitle from this section.

Comments

Just what I needed! So easy, and saved me from mucking about in the template files.

Submitted by Guest (not verified) on Thu, 12/30/2010 - 14:14

This just doesn't work for me.
Reaction - Theme - Class Section "Smthing"
Reaction - Block - Some blocks

Condition - Path - example/*

If there is site with path example/ex1 it will just add defined blocks, but not the class to body_classes. When i look with firebug there is nothing.

Submitted by Guest (not verified) on Sun, 01/30/2011 - 05:33