How to insert a block into a node or template in Drupal 7?

Solutions

This appears to be the solution for inserting blocks into templates for Drupal 7, but it seems a bit clunky and I have no idea about impact on performance:

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

If anyone has a better procedure, please do add.

D7:

<?php
  $block = module_invoke('module_name', 'block_view', 'block_delta');
  print render($block['content']);
?>

'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/webform/client-block-11/configure

In this example, 'webform' is the module's name, '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.

More information: http://drupal.org/node/26502

With wrburgess's answer you may get an error if your server is using a newer version of PHP.

Strict warning: Only variables should be passed by reference in include()...

This is what I did to not cause/get rid of the error.

  <?php
    $blockObject = block_load('views', 'block_name');
    $block = _block_get_renderable_array(_block_render_blocks(array($blockObject)));
    $output = drupal_render($block);
    print $output;
  ?>

Similar questions

How can I insert a block into each page of a view if the page is loaded via ajax?
I am trying to insert a SimpleAds block for each page of a View. But pages are loaded via AJAX using infinite pager. How can I insert a SimpleAds block into each dynamically loaded page of results?
Insert block content into the $content variable to be indexed by search
I have a block that is generated by a view. It brings in the author's name and other information for the specific node that is being viewed. The problem is that the block data is not indexed by drupal since it is not in the "content" of the page. How can I get around this? I tried moving the region to the node.tpl.php but that didn't help. Any sugg...
How to insert block into Article content type?
I haven't found any option or module to achieve this yet. I started to think I should do this by inserting code directly into article, but this would not be really good/easy solution on regular basis, for Adsense for example....
How to insert images into custom block type
This might be a really stupid question because I am overlooking something really simple but here is my issue. I have created a custom block in the custom block library in Drupal 8. I would like to insert images into the block from the images folder in my theme (not upload images using ckeditor). Normally in Drupal 7 I can manually insert the image ...
Drupal 6 - I am using drupal_execute to insert a CCK node into my site. Everything is working except taxonomy
This is a Drupal 6 site. I am using drupal_execute to create a node programatically. The first line is working for field_prx_mp3_labels. The second (for taxonomy) is not. Here is what my select on the node add for my cck looks like: I have tried many many variations for line 2 (relating to the taxonomy). This comment seemed close but it hasn't work...
Drupal 7 - Insert taxonomy into node object
I have a script which successfully creates new nodes. But I'm having trouble setting the taxonomy before saving. I believe in Drupal 6 I would use this method. I think in Drupal 7 I would do this (my field name is Catalog) taxonomy_get_term_by_name doesn't seem to return the correct object to insert into the node object. If anyone can shed some lig...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.