Thursday, January 12, 2012

Placing the Contents of a Block in any Location

If you want to embed the contents of a block into a node, a custom block, or a page template, you can use the following snippets.

D6 and earlier:

$block = module_invoke('module_name', 'block', 'view', 'block_delta');
print $block['content'];

D7:

$block = module_invoke('module_name', 'block_view', 'block_delta');
print render($block);

To specify which block from which module, you simply edit the two following variables in the first line:

'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 6: admin/build/block/configure/webform/client-block-11
Drupal 7: admin/structure/block/manage/webform/client-block-11/configure

In this example, 'client-block-11' is the block's delta.

Custom blocks will have module name of 'block' and a number for a delta, which you can also find by editing the block.

For More Information Please Click Here