How to add regions in drupal

19 Jun


This is the blog for those who use pre-written Drupal themes on Drupal.org or from some other sources, but want to add a region in the theme, say for example you want to add add region above the content region.

So now we are here to add our own region in drupal theme, where you can have any block in that region.

Well, here we go.

I suppose you are using Drupal’s Garland theme while writing this blog, These steps can be applied on any other theme also.

You need to modify 2 files in your theme

Inside garland.info, add the line with myregion (You can use any name as you want) :

When declaring a new region for the first time via the theme’s .info (i.e garlandd.info) file we must also declare all of the default regions as well as the new region. So, we must add:

regions[left] = Left sidebar
regions[right] = Right sidebar
regions[content] = Content
regions[header] = Header
regions[footer] = Footer
regions[myregion] = Above Content Area

So finally your garladn.info will look like below.

////////my garlad.info file start/////////
; $Id: garland.info,v 1.5 2007/07/01 23:27:32 goba Exp $
name = Garland
description = Tableless, recolorable, multi-column, fluid width theme (default).
version = VERSION
core = 6.x
engine = phptemplate
stylesheets[all][] = style.css
stylesheets[print][] = print.css

regions[left] = Left sidebar
regions[right] = Right sidebar
regions[content] = Content
regions[header] = Header
regions[footer] = Footer
regions[myregion] = Above Content Area

; Information added by drupal.org packaging script on 2009-04-30
version = "6.11"
project = "drupal"
datestamp = "1241050838"
////////my garlad.info file end/////////

Now open page.tpl.php:

And add code below in the HTML where you want your region to be displayed.

<?php print $myregion; ?>

In this case I will add it above content area in the HTML.

Please note as that you need to clear Drupal’s cache in order to see the newly created region in the blocks list.

You can leave a comment if you need any more information on this.

Thanks

One Response to “How to add regions in drupal”

  1. chaitra July 26, 2011 at 5:34 pm #

    Thank you Sachin :)

Leave a Reply

*