Adding Custom Regions for Blocks

Blocks can appear anywhere you want them to in your theme. By default, Drupal offers five regions to which blocks can be assigned: left sidebar, right sidebar, header, content, and footer. With just two quick alterations to your theme, you can add custom regions to this list, allowing you to place blocks anywhere on the page.

The first step for adding a custom block is to add a function to your theme's template.php file. This function is named theme_regions(), where theme is replaced with the actual name of your theme. For Blumarine, this would be bluemarine_regions(). The function must return an array of custom regions that will be added to the list of available regions when you configure blocks from the block administration page (admin/block).

The second step is to add a line of PHP to your page.tpl.php file where you want blocks in the custom region to appear:

This will print all of the code for the blocks that have been assigned to that particular region. You may add as many custom regions to your theme as you like. Exercise 5-4 demonstrates how to do this.

0 0

Post a comment