Drupal - How do I create custom regions in a theme?
You define regions in your theme .info file. See: Structure of the .info file
You then need to put the relevant template tags in your page.tpl.php file.
So for example if you defined the region sidebar
in your themes .info file, you would then add: <?php print render($page['sidebar']); ?>
to the relevant place in your page.tpl.php.
One other point: Don't miss the required regions!
regions[content] = Content
regions[help] = Help
regions[page_top] = Page top
regions[page_bottom] = Page bottom
More on this can be found at http://drupal.org/update/themes/6/7#closure.
To clarify on this point: If you define your own regions, you need to define all that you are using, including those that are required. In other words, you cannot just define additional regions: If you define any, you must define them all.
Creating a region for a Drupal 7 theme is not different from creating a region for a Drupal 6 region; the differences between Drupal 7 and the previous versions are essentially:
- The regions are not defined using a
mytheme_regions()
function as it was done in Drupal 5, but they are defined in mytheme.info usingregions[]
directives, which is what is done also with Drupal 6 themes. - The regions are rendered using the Drupal function
render()
, instead of printing the content of a variable.
The default Drupal 7 regions are the following ones:
regions[header] = Header
regions[highlighted] = Highlighted
regions[help] = Help
regions[content] = Content
regions[sidebar_first] = Left sidebar
regions[sidebar_second] = Right sidebar
regions[footer] = Footer
Drupal 7 core themes now include a region named 'highlighted' which uses the same display as the mission statement area in Drupal 6; they also include a region named 'help', that by default has the same content of the $help
variable used by Drupal 6.