Currently, core adds a wrapper to regions, even if they are empty.
For example, this is the region page_top:

   <div class="region region-page-top"> 
  </div>

This is added by printing the variable $page_top, called from html.tpl.php (inside system module folder). To reproduce, just visit the front page without being logged in. It is not a Bartik or Garland issue, because it happens in all themes.

Gabor and I thought of a few places to fix this bug, but all seemed impossible to use:

  • system_page_alter in system.module
    This functions adds a theme wrapper to regions. This would be the best place to fix it, however here we don't know if it has any content.
  • html.tpl.php
    We could add an if(!empty($content) around $page_region. However, because $content already contains the theme wrapper, it's not empty.
  • template_preprocess_region in theme.inc
    This function prepares the values before theme_region is called. It is too late too interfere, because Drupal already decided to call the region function.

My only solution was to add a check in region.tpl.php. Ideally, we should do this in an early phase, but couldn't find where to solve this. If anyone has a better solution, please jump in!

CommentFileSizeAuthor
empty_region_wrappers.patch638 bytesBarisW

Comments

seutje’s picture

subscribe

BarisW’s picture

Status: Active » Needs review
dawehner’s picture

I cannot reproduce the problem on a clean drupal7 installation.

BarisW’s picture

Status: Needs review » Closed (fixed)

I see that is has already been fixed.
The code in region.tpl.php is now:

<?php if($content): ?>
  <div class="<?php print $classes; ?>">
    <?php print $content; ?>
  </div>
<?php endif; ?>

The if($content) is new, and does the same as my proposal.