Template files for regions (e.g. region-right.tpl.php)

Events happening in the community are now at Drupal community events on www.drupal.org.
barobba's picture

In D6, the place to theme an entire region is in the page.tpl.php file, but I like having a little more flexibility.

So, I created a module that lets me define a region-right.tpl.php template file, for theming an entire region. This way, even if I have several "page" template files, the regions can be maintained with a separate template file without having to copy the region's HTML to each "page" template file.

Does anyone know of a module that does this already? Or, how this can be done in D6, without creating a special module?

(I tried searching for a module that can do this, but I am having a little difficulty due to low-level nature of this module idea.)

Comments

You're talking about the

WebNewCastle's picture

You're talking about the block regions? You can do this with block templates: block-right.tpl.php, block-footer.tpl.php, etc.

I don't think it wouldn't be

barobba's picture

I don't think it wouldn't be the block template, because that would just theme the block in that region. Instead, I would like to theme the region.

The Zen theme actually

Garrett Albright's picture

The Zen theme actually supports this all inside the theme layer; you can use template files like region-first.tpl.php. Perhaps you could look to that for inspiration.

That is good to know, and it

barobba's picture

That is good to know, and it is another reason to start using Zen.

So, now I am curious. Would there still be a need for a module that turns on theming of regions?

A. Starting a theme from scratch, designers might want to inherit from the Zen theme.
B. Using an existing theme would mean the theme is already designed.
C. Inheriting from a non-Zen theme. This might warrant a module that creates region-level theming.

The third option would still merit a region-level theming module.

Is anyone familiar with the

barobba's picture

Is anyone familiar with the Display Suite? Does this module turn on region-level theming? How would that be implemented? Also, it is possible Panels 3 turns on region-level theming. Does anyone know?

In case anyone is curious,

barobba's picture

In case anyone is curious, the implementation for this module would be very simple. Here is how I would implement it.

<?php
function themeregions_preprocess_page(&$var) {
 
$current_theme = $GLOBALS['theme'];
 
$regions = system_region_list($current_theme);
  foreach (
$regions as $region => $description) {
   
$var['region'] = theme('region', $var['$region'], (object)$var);
  }
}
?>

Then, I would create a theme function: theme_region( $parsed_blocks, $page ), that would simply return the parsed blocks. It's simple, but this now creates the opportunity to override the region using theming.

themes and theming the region

Pilot's picture

Hi Barobba - thank you for the code above. I want to just briefly relate my experience with the issue, but as I put it down six months ago, I am sketchy on the coding details.

I built a theme (currently in a late alpha state - I will publish it as "Tao" with appropriate nods to Zen as soon as it qualifies as a beta), and I was particularly keen to see Zen's region templates (part of why I used Zen as a foundation, though not as a "base"). However, I could not get drupal to recognize my calls to a region preprocess function, and I am not sure Zen even got that working or not. I haven't had a chance to get back to it yet.

For what it is worth, I suspect that an overview of how d6 treats regions and where in the process scheme one needs to go to affect region based processing (including region template introduction) would be far more helpful than a module. I will probably try to incorporate your code above, and if I can get it working will write a blurb on what is going on for other themers.

In D7, this is solved and the

barobba's picture

In D7, this is solved and the template file is called region.tpl.php (I hope someone backports this as a module. I could probably do it, if there is any interest.)

For my purposes right now, it turns out that in D6 the regions ARE themed with the theme_blocks() function. The function name is the pluralized form of the word "block", so "blocks" (instead of being called "region"). The two functions to look at are in the "theme.inc" file:

  • template_preprocess_page()
  • theme_blocks()

Thank you Garrett Albright and Pilot. After your suggestions, I decided to fire up the debugger.

I would love a D6 module that could do this

hellolindsay's picture

I would love to have a D6 module that allow for region.tpl.php and region-[name].tpl.php - i was just looking for this functionality...

Where is the "blocks" theme

hellolindsay's picture

Where is the "blocks" theme entry defined? I can seem to find any hook_theme function that defines it. Anyone know where that is?

common.inc

littleviking001's picture

drupal_common_theme() in common.inc http://api.drupal.org/api/function/drupal_common_theme/6

That function gets called by system.module's hook_theme() call. http://api.drupal.org/api/function/system_theme/6

The theme function itself is in theme.inc http://api.drupal.org/api/function/theme_blocks/6

Hi LittleViking. I think you

barobba's picture

Hi LittleViking. I think you are talking about something slightly different. The theme_blocks() function is a function, which is not the same as a template file for regions. It's important to distinguish theme functions from template files.

You might want to try

barobba's picture

You might want to try starting with the "Zen" theming kit. It already has support for regions, it's well-maintained, and it has a pretty good following.

Adding region.tpl.php to D6

hellolindsay's picture

Before doing this properly, I want to do it by changing core. I've changed drupal_common_theme() in common.inc so that 'blocks' calls a template file:

// ...
'blocks' => array(
  'arguments' => array('region' => NULL),
  'template' => 'region', // added
),
// ...

I then added a default 'region.tpl.php' to modules/system folder - this works, the default region.tpl.php file is loaded as expected when I clear my theme cache.

Next, I added a custom region.tpl.php to the current theme - but this file is not being loaded. Is there something else I need to do to make this work?

Lindsay

region.tpl.php in D6

rj's picture

If anyone else is trying to do this, here's how I did it.

--

R.J. Townsend

Contributed Module Ideas

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: