Programatically retrieve a block and print it in a page I have a form, generated by the Webform module, which is available as block. Now I want to retrieve the form itself and print it in a page.

How can I achieve this, programmatically? I'm using Drupal 7.
I'm not sure on which page you want to print the block. This is an example that prints the block in a custom page.

/**
 * Implements hook_menu().
 */
function mymodule_menu() {
  $items = array();
  $items['my/page/path'] = array(
    'title' =&gt; 'Block in A Page',
    'page callback' =&gt; 'mymodule_block_page',
    'access callback' =&gt; TRUE,
  );    

  return $items;
} 

/**
 * The page callback which display the block
 */
function mymodule_block_page(){ 
  $block = module_invoke($module_name, 'block_view', $delta);

  return $block['content'];
}


hook_menu() registers a menu path which will display the block. mymodule_block_page() is invoked when the menu path is accessed like http://example.com/my/page/path.

module_invoke($module_name, 'block_view', $delta); will return the block ready to render. Please find out the module name and delta. I guess $module_name would be webform. If you go to the block configuration, e.g. admin/structure/block/manage/comment/recent/configure, the module name is comment and the delta is recent.

If you want to print the block on every page except the front page, create a variable in hook_preprocess_page() of template.php.

function MYTHEME_preprocess_page(&amp;$variables) {
  if (!drupal_is_front_page()) {
    // It is not the front page.
    $block = block_load('module_name', 'block-delta');
    $variables['myblock'] = _block_get_renderable_array(_block_render_blocks(array($block)));   
  } 
}


In page.tpl.php, you can place the following code snippet where you want.

&lt;?php if (isset($myblock)): ?&gt;
  &lt;?php print render($myblock); ?&gt;
&lt;?php endif; ?&gt;