[Drupal] How to create custom regions for a theme in Drupal 7?

| | 1 min read

Drupal theme regions are specific areas defined in a theme into which we place blocks. We can create several regions based on our layout requirements. We define the regions in the theme's info file.

For example,

regions[menu] = Menu
regions[header] = Header
regions[content] = Content
regions[rightsidebar] = Right sidebar
regions[leftsidebar] = Left sidebar
regions[footer] = Footer

In above example we have added 6 regions and we print these regions in our page.tpl.php file as well. For that you need to use specific tags in your theme template file.

layout.jpg

For example, if you have defined a region 'rightsidebar' in your theme's info file, use:

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

to print the region in the page.tpl.php.

Similarly, we can print all the regions in the template file. These regions render in the content part only. We can place block's to these regions (Go to, Home » Administration » Structure: Edit Blocks). It is possible to add multiple blocks to a single region. So don't try to add region for all the existing blocks. Add region's corresponding to your required layout.