logo
Published on Technical articles on: Windows servers, Apache Web Server, MySQL, PHP, IIS (http://www.sitebuddy.com)

Custom regions in Drupal

By chris
Created 13 Mar 2006 - 11:12pm

Here is an executive summary of this feature using phptemplate.

1) In the file \themes\engines\phptemplate\phptemplate.engine
Find the function function phptemplate_regions().

It looks like this:
function phptemplate_regions() {
return array(
'left' => t('left sidebar'),
'right' => t('right sidebar'),
'content' => t('content'),
'header' => t('header'),
'footer' => t('footer')
);

}

Simply add a new region (example: Visible name: Header Ads, internal name header_ads) like so:
function phptemplate_regions() {
return array(
'left' => t('left sidebar'),
'right' => t('right sidebar'),
'content' => t('content'),
'header' => t('header'),
'footer' => t('footer'),
'header_ads' => t('Header Ads')
);

}

2) Add the code (in any of the *.tpl.php template):
<?php print $header_ads;?>
wherever you want to display your new region.

3) Now in the "Administer-->blocks" you will see the new region "Header Ads" you can add any block to that new region.

Voila!

Note: By looking how other regions are handled you can add styling (style.css support) and conditional statement, example:
 <?php if ($sidebar_left) { ?><td id="sidebar-left">
<?php print $sidebar_left ?>
</td><?php } ?>

Just replace sidebar_left with your new region name (example: header_ads).

 


Source URL:
http://www.sitebuddy.com/drupal/theme/custom/region/phptemplate/1