I know how to enable blocks in node.tpl.php. Add like below in template.php

function phptemplate_preprocess_node(&$variables, $hook) {
$variables['aregion'] = theme('blocks', 'aregion');
}

But in Drupal7, this way don't work. How to add a block area in node.tpl.php or directly include a block in node.tpl.php of Drupal7.

Thanks very much!!!

Comments

nevets’s picture

Do you have render($aregion): in node.tpl.php?

mayank-kamothi’s picture

Hi,efarseer

function your_theme_name_preprocess_node(&$variables) {

if ($blocks = block_get_blocks_by_region('your_block_region_machine_name')) {
  $variables['<variable_name>'] = $blocks;
  $variables['<variable_name>'] = $blocks;
  $variables['<variable_name>']['#theme_wrappers'] = array('region');
  $variables['<variable_name>']['#region'] = 'your_block_region_machine_name';
  }
}

then invoke this function inside your node.tpl.php

<?php print render($banner_space); ?>

Mayank Kamothi

efarseer’s picture

Thanks a lot for the detailed description, it helps a lot.

pzula’s picture

I followed the directions, but I'm not getting any output. Any clues?

In template.php:

function psrmc_preprocess_node(&$variables) {
if ($blocks = block_get_blocks_by_region('sidebar_first')) {
  $variables['$first_block'] = $blocks;
  $variables['$first_block']['#theme_wrappers'] = array('region');
  $variables['$first_block']['#region'] = 'sidebar_first';
  }
}

In my node.tpl.php:

<?php print render($first_block); ?>

zvischutz’s picture

2 small comments :
1) Clear your caches before testing
2) There is a duplicate code line in your snippet , It works with only one line of course.