Inserting a block into a content template

Here's a way to insert a block into a Drupal 7 content template, ie. a node--content_name.tpl.php file.

  • Go to the block you want to add in the blocks admin area (/admin/structure/block) and click 'configure'.
  • The url will be something like: /admin/structure/block/manage/views/bloggers_account_views-block_1/configure
  • The below code will insert the block
<?php
  $block = module_invoke('views', 'block_view', 'bloggers_account_views-block_1');
  print render($block);
?>
  • views = the name/type of module (module folder name), eg. 'views', 'search', 'user', 'comment', 'webform'
  • block_view = type of view
  • bloggers_account_views-block_1 = the block delta, ie. the machine name of the block

Custom blocks will have a module name of 'block', and a number for the delta. Again you can find this by editing/configuring the block.

Justin Chevallier

Justin Chevallier

Avid Drupal site builder & user for +10 years.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.