Drupal - creating new regions

By default, Drupal comes with 5 content "regions": header, footer, left sidebar, right sidebar, and content. In many cases it is convenient to have several additional regions for more granular control over content location.

 

Sometimes we need to have certain blocks to always appear above or below the content, so let's add a few new regions!

 

For Drupal 5.x:

Open the template.php file in your theme's folder and add the following function:

 

function themeName_regions()
{

return array(

'left' => 'Left sidebar',
'right' => 'Right sidebar',
'content' => 'Content',
'header' => 'Header',
'footer' => 'Footer',
'top_content' => 'Top Content',
'bottom_content' => 'Bottom Content'

);

}

 

Now just replace 'themeName' with your theme's name, and you're good to go!

 

For Drupal 6.x:

Drupal 6 comes with a new 'theme registry,' so the process is slightly different from the one for Drupal 5.x. Open the .info file in your theme's folder, and add the following:

 

regions[left] = Left sidebar
regions[right] = Right sidebar
regions[content] = Content
regions[header] = Header
regions[footer] = Footer
regions[top_content] = Top Content
regions[bottom_content] = Bottom Content

 

Whenever you create new theme functions or templates in Drupal 6 you must clear the registry by one of the following two methods:

  • The clear button located at "Administer -> Site configuration -> Performance"
  • Calling drupal_rebuild_theme_registry(). (hint: place this at the top of your template.php file while you're developing the site & remove from production)

You will now have two additional available regions on the block configuration page.

 

Update: At this point the regions are available, but are not being output anywhere, so let's open up page.tpl.php and add the following:

 

<?php
print $top_content;
print
$bottom_content;
?>

 

(Thanks for the reminder, eL!)

Comments

new region

Hey, and what about to add something to page.tpl.php? :)

Of course! Count on me to

Of course! Count on me to forget the most important step ;). Thanks!

Thanks for your info, here is a another detailed tutorial.

Thank you for your info, i have applied it to Marinelli Theme and made a tutorial to solve a feature request in Drupal Forums.
Of course i mentioned this link at the end of the tutorial!

You may read the tutorial about applying regions in Marinelli theme at:

Blocks above (before) main Content. (Marinelli theme, but think it works for any theme)
http://drupal.org/node/292028

Thanks and see you!

Claudio Gaston Abraham
Argentina - South America

Thanks for the link and

Thanks for the link and tutorial, mrbrowny! I'm sure it will be useful to people working with Marinelli.

New Regions not working as expected (5.x)

Hi, I used your code and can see the new regions show up on the Blocks page, but when I try to display something in Top Content it shows up at the bottom of the page. Right now I have a Time Warner Cable ad in that position. You can go to my page and see. I am using the Marinelli theme and Drupal 5.x.

i figured it out

you neglected to mention that when you place the print commands in the code, "print top content" should be ABOVE "print content" and "print bottom content" should be BELOW "print content".

i found a clue to this information at http://drupal.org/node/105963

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
3 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.