Stuart McCulloch AndersonStuart McCulloch Anderson Stuart McCulloch Anderson
  • Welcome to StuAnderson
    The ma’r I see of some fock, the ma’r i like my dog

    30Jun Embedding Views and Blocks into Drupal template files


    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)

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

    Embedding Nodes is also pretty easy aswell:

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

    Stuart McCulloch Anderson

    E stuart at anderson dot eu dot comA +44 131 208 3764