Creating New Block Region in Drupal 7

Posted on May 6, 2015 by Suresh Kamrushi in PHP
  

Creating a custom or new block in your Drupal 7 template is very easy. Follow the steps to create it:

Step 1. Go to your theme folder and look for “.info” file. I am using theme “corporate” so info file will be located “themes\corporate\corporate.info”. You will see different location/blocks in your theme. like below:

regions[header]         = Header
regions[content]        = Content
regions[help]           = Help
regions[footer]         = Footer

Step 2. Add your block into the file like below:

regions[header]         = Header
regions[content]        = Content
regions[help]           = Help
regions[footer]         = Footer
regions[welcome_header] = Welcome Header

Step 3. Update your template file with this new block. Open “page.tpl.php” located in “themes\corporate\templates” and add your block like below:

<?php if ($page['welcome_header']): ?>
<div id="welcome_header" class="welcome_user">
<div class="section">
<?php print render($page['welcome_header']); ?>
</div>
</div>
<?php endif; ?>

Step 4. Release the cache from admin -> Configuration -> Performance. And click “Clear Cache” button to release the cache. Now if you go the block in structure, you can see “welcome Header” section is getting listed in region drop down. Now you can select “Welcome Header” region for your block.

New Block Region

New Block Region

Tagged as