Tuesday, August 30, 2011

Drupal 7 adding a body class that tells us whether a region is empty of blocks

Sometimes, especially in the style.css file, there is a need to understand whether a theme region is empty. A good solution to achieve this is to add a body class. In order to achieve this, you could make use of Drupal 7 template_preprocess_html(&$variables)

Just add to your template.tpl.php file of your theme the following function:

function YourThemeName_preprocess_html(&$variables) {
if (empty($variables['page']['RegionName'])) {
$variables['classes_array'][] = 'YourClassName';

No comments: