Creating new Drupal 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 [code]template.php[/code] file in your theme's folder and add the following function:

[code]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’ ); } [/code]

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 [code].info[/code] file in your theme's folder, and add the following:

[code]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 [/code]

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 [code]template.php[/code] file while you're developing the site & remove from production)

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

[code]print $top_content; print $bottom_content; [/code]

(Thanks for the reminder, eL!)