Tuesday, April 24, 2018 04:25 am EDT

Adding new Regions to a Drupal theme

Bri's picture

Have you ever wanted to add a new region to the theme your using? Well in Drupal 6 you can, and it's not very difficult. A region is a section of your template where information, such as blocks, can be placed. By default there are 5 pre-defined regions. They are as follows:

  • header: This region describes the header area of the template.
  • content: This describes the main area of the page.
  • left: This describes one sidebar, typically for block placement.
  • right: This describes the second sidebar, typically for block placement.
  • footer: The footer section contains information that should usually appear after the rest of the content.

Your themes .info file contains the directive letting Drupal know which regions are to be available. If your theme doesn't contain any statements such as :

    regions[header] = header
    regions[content] = content

This is because these are the defaults. They will be available regions even if they are not present. If you wish to define your own regions, however, you need to include them here. If we wanted to add a region called "Content Top", we would open the .info file and add the line:

    regions[content_top] = Content Top

The "content_top" is the internal name of the region, and will correspond to the variable that gets used in the template files. The "Content Top" is the name you have given to this region and will show up on the blocks page when displaying the various regions.

You now need to locate your page.tpl.php template and add the region to it. To add the region, you only need to find the area that you would like to add it to. In our example, putting it right above the content area would make sense. Locate the section in your page.tpl.php file marked as:

 


<?php print $content; ?>

Before this line of code, add the following:

 


<?php if ($content_top): ?> <div id="content-top">
<?php print $content_top; ?>
</div> <!-- content-top -->
<?php endif; ?>