How to Create a New Block Region in Drupal 7

Adding a new block region to your Drupal 7 theme is simple:

To first see which block regions are currently defined, go to your admin panel, click on structure in the main menu, and then on blocks on the page that appears.

Drupal 7 block regions

Drupal 7 block regions

For a visual representation of your theme’s block regions, click on Demonstrate block regions at the top of the page.

Drupal 7 block regions demonstration

Drupal 7 block regions demonstration

 

Now to Add a New Block Region

1. Open you theme’s .info file (sites/all/themes/[your-theme]) and add a new region to go with the others in there already. In bold is the region I added–subbanner.
regions[header] = Header
regions[banner] = Banner
regions[subbanner] = Subbanner
regions[content] = Content
regions[sidebar] = Sidebar
regions[footer] = Footer
regions[copyright] = Copyright

Update the file on your server.
2. Open your page.tpl.php file (sites/all/themes/[your-theme]/templates/pages), and add the markup that will hold your new block. When adding to a theme’s file in situations where you’d like to add a similar component to others already present, it’s often pretty intuitive as to how to go about it. In my case, I added a subbanner block to go directly below the banner block, and so had only to search for ‘banner’ in page.tpl.php and found two areas to replicate.

The first:


<?php if($page['banner']):?>
<?php print render($page['banner']);?>
<?php endif; ?>
<?php if($page['subbanner']):?>
<?php print render($page['subbanner']);?>
<?php endif; ?>

and the second:


<?php if($page['banner']):?>
<?php print render($page['banner']);?>
<?php endif; ?>


<?php if($page['subbanner']):?>
<?php print render($page['subbanner']);?>
<?php endif; ?>

You will now see your new block region defined if go back to your admin panel and click on structure in the main menu, and then on blocks on the page that appears.

New Drupal Block Region

New Drupal Block Region

3. Once your block region is created, you can then create a new block, as I’ve done, and named ‘Quick Quote Form’ as illustrated in the screenshot above.

That’s pretty much it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s