How can I add a css class (.empty-panel-region) to Panel's regions that don't contain any panes?


The following works with all standard renderers (default/IPE).

There is no preprocess possibility for the regions, so some extra work is needed.

First add the following preprocess function to your template.php of your theme or your own module (change MY_THEME accordingly).

 * Implements hook_preprocess_HOOK().
function MY_THEME_preprocess_panels_pane(&$vars) {
  // Determine if a panels panel (region) is empty.
  // Every pane needs to be checked for content.
  // Set the result on the panels display object.
  if (empty($vars['content']) || (isset($vars['pane']->IPE_empty) && $vars['pane']->IPE_empty)) {
    if (!isset($vars['display']->panel_is_empty[$vars['pane']->panel]) || $vars['display']->panel_is_empty[$vars['pane']->panel] ) {
      $vars['display']->panel_is_empty[$vars['pane']->panel] = TRUE;
  else {
    $vars['display']->panels_is_empty[$vars['pane']->panel] = FALSE;

Then you can use the data in the $display->panel_is_empty array in your PANELS-LAYOUT.tpl.php files to conditionally add extra classes. (Change 'PANEL' to the specific region.)

<div class="panel-panel <?php print !empty($display->panel_is_empty['PANEL']) ? 'panel-panel-empty' : ''?>">
  <?php print $content['PANEL']; ?>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.