Go to your blocks admin-overview, and click 'configure' on the block you like to have in content area.
Click on configure link, and identify the last two items in the URL.
For instance, let's say you want to configure the calendar block. After clicking 'configure', the URL will resemble: admin/build/block/configure/calendar/2 ('calendar' is the target block and '2' is the target block id).

To print this block in any content area, use the following php code:

<?php
$block = (object) module_invoke('calendar', 'block', 'view', '2');
print theme('block',$block);
?>

More complicated way...

Ok, you most likely want to generate a block using code. How to do it?

You need a module and a delta. For example, the "Powered by Drupal" block's module is system and delta is 0. Another block example is one produced by Views: module is views and delta is generic_name-block_0.

Once you know the module and the delta, it's a simple matter of creating the correct $block object and passing it to the theme() function. The trick is you need to send an object with the right parameters. The code below should get you started. Drupal 7 may be different.

<?php
// setup vars
$block = new stdclass; // empty object
$module = 'system';
$delta = 0; // could also be a string

// renders the "Powered by Drupal" block
// @see hook_block()
// @see module_invoke()
$array = module_invoke($module, 'block', 'view', $delta);

// must be converted to an object
// @see block_list()
if (isset($array) && is_array($array)) {
  foreach ($array as $k => $v) {
    $block->$k = $v;
  }
}

$block->module = $module;
$block->delta = $delta;
$block->region = 'whateverYouWant';

echo theme('block',$block);
?>

Another Alternative

To do this without using php permissions, you can enable reptag.module, which provides a lot of token replacements, and:

block.tags
Inline Blocks ({BLOCK:1}, {BLOCK:menu:2} ...) Embed a Drupal block inline anywhere in your page.

Comments

RoyBatty’s picture

You say "To print this block in any content area, use the following php code:" and there goes some php code. Where should I put it? Should it be in Block Body where is also my block's HTML?

KiwiLeex3’s picture

I am adding on to Roy's comment. For people who have been following the handbook in order, this PHP code comes out of nowhere and we have no idea what to do with it. Please add in a link before your tutorial on how to edit content using PHP.

hampshire’s picture

The php code goes in your content area, so for example if you are creating a page then it could go in the body section and you would have to also enable the php filter module and use php as input type.

david.mccandless’s picture

If you want to change the title or subject of the block, try the following:

<?php
  $block = (object) module_invoke('calendar', 'block', 'view', '2');
  $block->subject = 'My New Title';
  print theme('block',$block);
?>
R2-D8’s picture

This articel is not 100% right.

I've lost hours struggling around to get the "node_licence"-block from the "creativecommons"-module shown.
The configuration path of one of it's blocks is:
http://DOMAIN.TLD/admin/build/block/configure/creativecommons/site_license
As you can see there is no target integer as block id. And working with the text ('site_licence') instead doesn't work.

Ok- a simple "0" did it, but how should one know. Especially beginners could loose all hope/will with such a tiny crap.

So after that:

How can one surely identify those target id's?
Or do I have to waste time trying???????

pfrenssen’s picture

Just look in the database. The "blocks" table lists all the blocks alongside their deltas. For example to show all blocks that belong to the 'creativecommons' module:

SELECT * FROM block WHERE module = 'creativecommons';

Z2222’s picture

Is it the same for Drupal 7? I'm using this code in a node--activity.tpl.php file:

    $block = (object) module_invoke('author_pane', 'block', 'view', "delta-0");
    print theme('block',$block);

and getting this error:

Fatal error: Cannot use object of type stdClass as array in /home/****/public_html/*****/includes/theme.inc on line 813
pfrenssen’s picture

    $block = module_invoke('MODULENAME', 'block_view', 'DELTA');
    print render($block);
Thremulant’s picture

I insert this code and works fine, my problem is that the block is only visible for some pages, how can I keep this code but make the block only visible for those pages?

Thanks