Skip to main content

Add new Region to Drupal Theme

Add new Region to Drupal Theme

There are loads of themes available, but you’ll rarely find one that’s exactly what you want (or what the client wants), straight out of the bag… So at some point you’ll need to add a region, and this is how.

In each ‘theme’ you will have a .info file, a page.tpl.php file and the style sheet. The .info file will start with the name of you theme, so themename.info for example.

INFO
To add a new region called ‘Banner’, you open the .info file and you should see a section like:

regions[sidebar_first] = sidebar first
regions[sidebar_last] = sidebar last
regions[header] = header
regions[nav] = nav
regions[content_top] = content top
regions[content] = content
regions[content_bottom] = content bottom
regions[footer] = footer

To add our new region we just add it to the above like: regions[banner] = Banner
Note: the first ‘banner’ is all lowercase, no spaces, and the second ‘Banner’ is for display, so can have spaces, etc, just be careful with punctuation.

Your new region will now show on the ‘blocks’ page, and you can start assigning blocks to your new region. (Flush cache if it doesn’t show). However it won’t appear on the website pages yet.

PAGE TPL
In the page.tpl.php page, find the area you want the new region to show and paste the following:

<?php if($banner){ ?>
<div id="banner">
<?php print $banner; ?>
</div>
<?php } ?>

Note: The variable you used in region[] (banner) is also used here, but it has a $ sign in front. i.e. $banner. The first line in the code above uses if to check that something has been put in the banner region, (i.e. a block), and if it has, line 3 prints/writes it to the page as it’s being built. Lines 2 and 4 add the CSS div start/end with an id of banner so you can control it in the stylesheet by using #banner.

STYLESHEET
Add the following and amend it as you see fit:

#banner  { 
width: 960px;
height: 300px;
clear: both;
margin: 0;
padding: 0;
background: #f0f;
position: relative;
}

See? Painless really… If something isn’t showing, remember to flush the cache so the system loads the .info and template files again.

Main Category
  • Drupal
  •  
Secondary Categories
  • Drupal 6
  •  
 
Jon Moore

Search form

Jon Moore

Tips 'n' Snips

 
  • Home
  • General
  • Drupal
    • Drupal 6
    • Drupal 7
    • Module Building
  • HTML & CSS
  • Javascript
  • jQuery
  • PHP
    • Handy Functions
    • MySQL
  • WordPress
  • About
  • Contact

BBC Technology News

  • Ex-Nokia team makes rival smartphone
  • Yahoo to buy Tumblr for $1.1bn
  • VIDEO: Wikipedia founder on Yahoo's Tumblr deal
  • How Tumblr fell into Yahoo's hands
  • Pupils 'need early porn warnings'
More

Sitepoint

  • Even Better CSS3 Toggle Switches!
  • Introducing the new HTML5 template Tag
  • Crowdfunding a CSS Animation course – an experiment
  • Learn JavaScript Online
  • Does Grammar Even Matter Any More?
More

Heart Internet

  • New apprentice scheme at Heart Internet
  • Sale now on, get 50% off Web Hosting
  • 7 tips to kick-start your day in front of the computer
  • Link Friday Week #11
  • What makes a good Website of the Month contestant?
More
 

Backend Coders

  • PHP
  • Handy PHP Functions
  • PHP MySQL

Frontend Coders

  • HTML & CSS
  • jQuery
  • Javascript

CMS/CMF Systems

  • Drupal
  • Drupal 6 Specific
  • Drupal 7 Specific
  • Drupal Module Building
  • WordPress

About

  • Home
  • About
  • Contact
 

© Jon Moore 2013