Ways to print a block Drupal

Pinterest LinkedIn Tumblr

We can print blocks in drupal in different ways bases on block type.

Method 1:
$block = module_invoke('module_name', 'block_view', 'block_delta');
print render($block);
// example
$songs_added = module_invoke('views', 'block_view', 'songs_added-block');
print render($songs_added);
Method 2:
// relationsactivity
 //block_load($module_name, $block_delta)
  $block = block_load('heartbeat','relationsactivity');
  $renderable_block=  _block_get_renderable_array(_block_render_blocks(array($block)));
  print render($renderable_block);

‘module_name’ = The machine name of the module (i.e. the module’s folder name). This is true for core modules too, so for instance ‘search’, ‘user’ and ‘comment’ would all work here.

‘block_delta’ = The machine name of the block. You can determine what this is by visiting the block administration page and editing the block. The URL for editing a webform block, for instance, would be something like:

Drupal 7: /admin/structure/block/manage/*views*/*songs_added-block*/configure


Write A Comment