Ways to print a block Drupal

We can print block 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

Tags: 

Comments

Wow, that's what I was looking for, what a stuff!

present here at this weblog, thanks admin of this web site.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Syntax highlight code surrounded by the <pre class="brush: lang">...</pre> tags, where lang is one of the following language brushes: css, jscript, php.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.