Insert a block into a node or template in Drupal 7

This will show, how you can display a block in any template or node using PHP code.

To print the block you can use below code,

$addblock = module_invoke('addthis','block_view','addthis_block');
print render($addblock['content']);

addthis = "module_name" = This is module name can be found in block configuration URL or the name of the module's folder

block_view = Type of view

addthis_block = "block_delta" = This can also be found in the block configuration URL

*Configuration URL = Open blocks page in Drupal 7 which is "admin/structure/blocks", and click on "configure".

And for the blocks created from Drupal's admin panels you can use below code to render them,

 

$addblock = module_invoke('block','block_view','23');
print render($addblock['content']);
Author

Submitted by natamolestr on Sat, 02/20/2016 - 07:52

Permalink

Very well written!
I will immediately snatch your rss feed as I can not to find your
email subscription hyperlink or newsletter service.
Do you’ve any? Kindly let me know in order that I could subscribe.

Thank You for your comment sir. but I am sorry, I don't have any subscription system implemented. If you want you can either follow me (@umesh_24) or (@ultechspot). to get latest tricks update. Thanks!! :)