Embedding Views and Blocks into Drupal template files

Wednesday, 30th June 2010

This is the first official tutorial I am posting for Drupal and for the most part its for my own benefit as much as anybody else's. Recently while working on a number of separate projects I've had to look this information up and so I'm not putting it down here to save some time.

Drupal 6 makes this all pretty easy here is a brake down:

Views

To embed a view, simply put this code:

print views_embed_view('View Name');
Blocks

Embeding blocks is a little more work. You need to know:

1) Which module does the block belong to? (If you made the block yourself, then the module is 'block')

2) What is the block_id of the block? You can see this on the blocks page, just hover over your block. (It's not always a number)

$block = module_invoke('block' ,'block', 'view', 3); print $block['content'];
Nodes

Embedding Nodes is also pretty easy aswell:

$node = node_load(array('nid' => 2)); print $node->body;