Board logo

subject: Using Code To Display Drupal 6 Block [print this page]


In this post we are going to look at how to easily display Drupal 6 block using codes.

At times we all are required to have reminders on some apparently simple things. We are going to share one of those snippets of code that we find very useful and thus needed quite often. We decided to share it so that along with us, even you can locate it to utilize it in your use case.

While sharing it, its good to mention we used of most of the code/concepts from the comments at http://api.drupal.org/api/drupal/developer!theme.php/function/theme_block/6.

The below PHP code provides instances of the way to display Drupal 6 block using code in a simple manner. This can be something that you put in a Drupal 6 template file or a Drupal 6 theme function.

In case you simply want to get the content of the Drupal 6 block, then you may use the following code:

$block = module_invoke('MYMODULE', 'block', 'view', 0);

print $block['content']

And if you want to print the themed version of the Drupal 6 block, then you could make use this code:

// The name of the module implementing hook_block.

$module = 'MYMODULE';

// The delta of the block, may be a number such as 0 or 1, or may be a string

// such as 'mymodule_block' depending on how hook_block was implemented.

$delta = 0;

// Get the block as an object and set the module and delta properties.

$block = (object) module_invoke($module, 'block', 'view', $delta);

$block->module = $module;

$block->delta = $delta;

// Now you can print the themed block.

print theme('block', $block);

This is very simple, but indeed very useful. So, go ahead and make use of this easy yet useful technique.

Valuebound is a leading Drupal Development Company providing Enterprise Drupal web solutions. For more information on Drupal Development, contact us at info@valuebound.com

by: valuebound




welcome to loan (http://www.yloan.com/) Powered by Discuz! 5.5.0