How To: Embed a Region in a Node

By default, drupal provides a number of regions to put blocks in and lets you put them pretty much anywhere in the page you want to. But, there are a few exceptions to this rule. What if you want to put a region in a node? What if you want to put a region in between a node and the comments on that node? This may not seem so easy out of the box. Let's take a look at how to put a region in a node.tpl.php file.

Let's walk through a situation where I want to put a custom region between a node and it's comments. I could use this to place something like a block from the Similar by Terms module right under my posting.

I'll start by adding a custom region called node_region using hook_regions() in my themes template.php file.

<?php
function mythemename_regions() {
  return array(
      
'left_sidebar' => t('left sidebar'),
      
'right_sidebar' => t('right sidebar'),
      
'header' => t('header'),
      
'footer_message' => t('footer'),
      
'content' => t('content'),
      
'node_region' => t('node region'),
  );
}
?>

You'll notice that I defined the same regions that come by default as well as the new node_region. This function defines all the regions, not just additional ones. In this case, I defined the same ones that come by default and just added my additional region.

This now created the node_region so you can assign blocks to in on your blocks admin screen.

Next we need to make the variable $node_region accessible in the node.tpl.php file. To do this we use the function _phptemplate_variables.

<?php
function _phptemplate_variables($hook, $variables) {
  if (
$hook == 'node') {
   
$variables['node_region'] = theme('blocks', 'node_region');
  }
  return
$variables;
}
?>

This will made $node_region available in node.tpl.php files. This same concept applies for comments and most of those other non-intuitive places you may want to put a block where it isn't obvious how.

Note: This works for drupal 5. Implementing this is slightly different in drupal 6.

This is useful since you

This is useful since you could target a region to a specific node type and not have to bother with block admin settings. Thanks!

comment

Some essay help can save your time in writting article for different themes.

Any limo company offering

Any limo company offering unusually low prices likely has the oldest vehicles.scottsdale limo rental

I appreciate your writing

I appreciate your writing stuff!

Tim - essay writing services

i agree with your point. dog

i agree with your point.

dog food coupons

yeah agree...very useful

yeah agree...very useful

First and foremost, safety

First and foremost, safety should be the primary concern for the passengers and driver. Safety is often overlooked.scottsdale limo

Awesome!

Exactly what I needed! Great tip!

Glad to help

Glad I could help.

CqaCUelWMpqOVOBYk

Hello! Very good job(this site)! Thank you man.

This looks absolutely

This looks absolutely perfect. All these tinny details are made with lot of background knowledge. I like it a lot. Keep on taking action!
Funeral Insurance

Weight loss pills Lida

Weight loss pills Lida

good info.

dbbdvbdfi

great

Put it on Drupal.org!!!

Hey Matt. I think this should really be moved to the Drupal.org handbooks, if it's not there already.

Added to d.o

Good call. I added it in a slightly re-factored form to drupal.org. You can find it at http://drupal.org/node/208869.

reallly!! nice

reallly!! nice information.

Drupal 6?

Could you possibly do a quick follow up to cover what's different in Drupal 6 for achieving this same effect? I'm trying to get ahead of the game for when it's released and this is a roadblock for a site I'm working on.

In The Next Few Weeks

In the next few weeks I can post about this.

almost too easy in Drupal 6

You just add your region to the .info file of the theme, and voila, the core system populates a variable for you of the same name, and your region will be there for drag-and-dropping blocks to it. Done :)

Still Need To Add It To Node Variables

The .info file lets you add the region. We still need to make the region available via mythemename_preprocess_node or a direct theme call in the node.tpl.php file.

I'll post more on that in a few weeks.

Please Man

Lookin forward to get it

thx's a lot

thanks for helpfull

thanks for helpfull article...

You Rock!

Thanks a lot..have been searching for days !

thanks!

thanks!

mcse mcts

Nice Article, informative

Nice Article, informative and interesting

Vizyondaki Filmler | Fragman izle | Sinema

essays

By learning these

By learning these technologies, you open up so much more possibilities than if you narrow yourself to a select few set of components.
Indian Patent Lawyers

hali yikama

thanks god

everything seems simple and

everything seems simple and straightforward, applying programming on your blog mother breastfeeding

yes

yes... thanks god we have such a nice opportunity to read this blog entry :)

Holy

Damn holy. Thank u

thank you

Nice information. Thank you.

Nice

Thanks for the useful post,sharing valuable information.Expecting more productive postings from you.

Reply

very vice sharing. boyacı

Hey everyone. Interesting

Hey everyone. Interesting idea for a blog. I have been checking out a lot of blogs and forums recently. Some are really informative some are entertaining and some are a real crack up. I've got to admit it, good job on this blog, I'll be sure to look in again real soon.

Thanks for the useful

Thanks for the useful post,sharing valuable information.Expecting more productive postings from you.

..

Thanks for the useful post,sharing valuable information.Expecting more productive postings from you.

Thank you for making this

Thank you for making this possible, appreciate every little info you share here, just keep updating.

Such an effective solution.

Such an effective solution.

Garza, the serenity ship

Garza, the serenity ship replica keychain 2008 AL

Very easy to follow.

Very easy to follow.

resources and information

resources and information aboutonline casino and marjiuana seeds on the internet right here .marijuana seeds.

Good Job essay help |

Variables looks easy.

Variables looks easy.