Skip to main content

How to embed a block in Drupal 7

Published on 28th April 2013

During my latest project I needed to have 2 webforms side by side on the same page. The solution I used was to embed the webform as a block into the node.

Firstly you need to make the webform available as a block. To do this go to your webform > form settings > advanced settings > and tick 'Available as block'

Place the code below straight into the node content or page.tpl.php (you must have text format set to PHP code)

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

Replace module_name with the machine_name of the module (i.e. the module's folder name). Examples include 'webform', 'search' and 'comment'.

Replace block_delta with the machine_name of the block. To find the machine name visit the block admin page and edit the block. For example...


client-block-7 is the block's delta.

The working snippet I used in my project...

  $block = module_invoke('webform', 'block_view', 'client-block-7');
  print $block['content'];

In this case 'webform' is the module's name and 'client-block-7' is the block's delta.