Designer, Coder & More...

Drupal: Print a block programmatically

Print a block in a template

Sometimes you need to print a block in a template. For example, inside a node.tpl.php file.

It's quite easy. In this example, we are going to print out a disqus comment block.

1. Go to yoursite.com/admin/structure/block

2. Get the url of the block you want to print. Make a note of the bold and italic elements the URL:
yoursite.com/admin/structure/block/manage/disqus/disqus_comments/configure

3. Use the following code in your tpl.php file. You need to insert the elements identified in step 2

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

Your block will now display.

style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-3945684648599994"
data-ad-slot="7784927124">