Profile picture for user admin
Daniel Sipos
03 Sep 2012

This tutorial will show you how to add a region to your Node template. That is, how to display, or call, a region in your node.tpl.php (rather than in your Page template: page.tpl.php). This might come in handy when for instance you want to display a block somewhere inside your node. I used it once to add a region for blocks at the end of my node content, but before the Comment section (which in the page.tpl.php is generally included in the main content variable).

Just like adding a new region to your Page template, you will first need to declare a new region in your theme.info file.

Next, you need to edit your node.tpl.php file (you can find that in your theme folder, possibly in the templates sub-folder). If you have custom node templates for specific Content Types and you want to call a new region in those, edit those (too).

Try to find this .php line: print render($content); This renders out the content of your node (which includes also additional fields that you added with CCK). You can use this to orient yourself and figure out where you want to display your new region. And the command to call your new region is:

print render(block_get_blocks_by_region('machine_name_of_your_region'));

print is simply the .php command that writes the content on the page whereas the next part is what is important in our case. You can wrap it in .html to have it displayed however you want. Then you can save and close.

Next, you just add a block to your new region and it should appear where you added it on your node.

Hope this helps.

NB: A good way to later manage your block display in regions is using the Context module.

Profile picture for user admin

Daniel Sipos

CEO @ Web Omelette

Danny founded WEBOMELETTE in 2012 as a passion project, mostly writing about Drupal problems he faced day to day, as well as about new technologies and things that he thought other developers would find useful. Now he now manages a team of developers and designers, delivering quality products that make businesses successful.

Contact us

Comments

Chris L 15 Jan 2014 19:17

Doesn't work with context

This doesn't seem to work with blocks assigned via context. Anyway, here's a solution:
https://drupal.org/comment/5354288#comment-5354288

Kryptum 31 Jan 2014 01:43

Amazing!

Amazing!
Thanks for the time to explain it. Exactly what I search for.

PhilS 29 Jul 2015 12:59

Preventing the error

Nice post. But since rendering regions directly will shoot an error message, you should declare it before rendering like so:

<?php
$region = block_get_blocks_by_region('lside-bottom');
print render($region);
?>

(from: http://drupal.stackexchange.com/a/23216/3125)

Gideon 14 Oct 2015 21:09

In reply to by PhilS (not verified)

Regarding the error message

Yes, indeed, and yes, this solves the error.

Thanks to all who contributed here.

David 25 May 2017 18:19

Niceeee!

I went through so many other approaches to achieve this that did not work. I was skeptical it seemed to straight forward. Every other approach required modifying the node preprocess... Worked great though!

Kushalappa 04 Jun 2019 10:00

facet api filter blocks

For facet api filter blocks, check boxes are not coming, when I render using above function

Add new comment