This is the first official tutorial I am posting, and I am posting it mainly for myself, since I've had to look this up numerous times. When doing projects for my clients, I often times need to embed or insert the contents of a block or View into a .tpl file. This is actually pretty easy in Drupal 6. Here is what you do:
VIEWS:
To embed a view, simply put this code:
print views_embed_view('View Name');
It's really that easy. Just type the name of the View you want to embed, and there it goes. For those of you who are inquisitive, the actual function call looks like this:
views_embed_view($name, $display_id = 'default');
BLOCKS:
To embed a block, it is a bit more difficult.You will need to know two things:
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'];
That is the gist of it. If you want to see what else is in the block that you loaded, just try a print_r($block). There are a few other things in there you might find useful.
NODES:
Embedding Nodes is also pretty easy:
- print $node->body;
There you go, that pretty much sums it up. You can use these in .tpl files or nodes if you have the php filter on.

What if the node you want to embed has php already on it?
The answer is:
<?php
$node = node_load(185); echo $node->title; echo node_view($node);
?>
Good point, Adam, the php in a node would simply be printed unless you use node_view().
When using
echo $node->title;andecho node_view($node);, the title appears twice: first as unformatted text, and then as anh1with a link to the source node. I'd really just like to turn off this second title that gets created withnode_view. Does anyone know how to do this?For a case like this, I would suggest using
print check_markup($node->body)Hi Leighton,
thanks for the tutorial.
How would you go about embedding Quicktabs into a node / page?
Any advice is appreciated.
cheers
Ed
Ed,
I've never used Quicktabs, but from what I understand, it isn't a node, it's a block. Try the block embed process explained here.
Sincerely,
Leighton
Post new comment