1

i have a dynamic block data (from database) for one of my modules and it is displayed in the right sidebar.

Now my template is changed and i want to integrate this block data into one of my .tpl files. How can i proceed?

apaderno
  • 28,547
  • 16
  • 75
  • 90
shasi kanth
  • 6,987
  • 24
  • 106
  • 158

2 Answers2

2

You have not specified the version of Drupal you are using, for Drupal 6 this would do it:

$block = module_invoke('views', 'block', 'view', 'block_name');
print $block['content'];

For drupal 7, you could try this (clunkier) approach:

$block = block_load('views', 'block_name');      
$output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));        
print $output;

Hope that helps!

Stephane Gosselin
  • 9,030
  • 5
  • 42
  • 65
  • Thanks, i am using drupal6, but the snippet you gave did not work... i got solution from here: http://api.drupal.org/api/drupal/includes--module.inc/function/module_invoke/7#comment-14599 – shasi kanth Jun 03 '11 at 15:16
  • 1
    I was going to edit the answer to correct the D6 code version, but the example on that page is the same as the one I posted, the only difference I saw was in the block name parameter. Did I miss something? *I should update the D7 version though*. – Stephane Gosselin Jun 03 '11 at 15:23
  • 1
    Thanks, and finally this is what i used to make it work: **module_invoke('', 'block', 'view', 0);** I suppose the first parameter must be the module name. – shasi kanth Jun 03 '11 at 18:33
1

In D6, if you want the block contents themed like a block:

$block = module_invoke('views', 'block', 'view', 'block_name');
print theme('block', (object) $block);
rcourtna
  • 4,589
  • 5
  • 26
  • 27