Search code examples
cssdrupaldrupal-7regions

How to add a class to a Drupal 7 region?


I am trying to add a .clearfix class to my footer region in a Drupal 7. Is there a way to do this?

I am currently using the following to print my footer region:

<?php print render($page['footer']); ?>

Which outputs:

<div class="region region-footer">
   <div id="block-1>....</div>
   <div id="block-2>....</div>
</div>

Solution

  • Copy region.tpl.php (found in modules/system directory) to your theme directory. Then copy everything inside it and create a new file. Paste into that file and make any changes you like to the template. Once finished, save it as region--footer.tpl.php and clear the cache on your site to see the changes.

    The region.tpl.php contains (along with a lot of comments explaining possible variables):

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

    So all you would need to do is add a class on that DIV.