Skip to content

Create a Custom Blocks in Drupal6

04/10/2011

Hi,

i just go through the hook_block and create a custom block in drupal 6. The custom module file as follows,

The custom.info file as


; $Id: shan.info,v 1.0 2011/10/04 19:32:28 Exp $
name = custom
description = this is my custom test module.
package = custom modules
core = 6.x

The custom.module file as


/**
* Implementation of hook_block()
*/
function custom_block($op='list', $delta=0, $edit=array()) {
switch ($op) {
// Declare the list of blocks to create
case 'list':
$blocks = array();
$blocks['custom_block1'] = array(
'info' => t('custom_block1 information'),
);
$blocks['custom_block2'] = array(
'info' => t('custom_block2 information'),
);

return $blocks;
// in this case assign the content for the listed block
case 'view':
switch ($delta) {
case 'custom_block1':
// assign the value for the custom blocak one.
$block = array(
'subject' => t('Title of custom block1'),
'content' => "content of custom_block one" ,
);
break;
case 'custom_block2':
// assign the value for the custom blocak two.
$block = array(
'subject' => t('Title of custom block2'),
'content' => "content of custom_block two" ,
);
break;
}
// all the value of the block passed in this variable $block
return $block;
}

}

Make the both files in custom folder as past the module in /sites/all/modules/custom. Install the custom module, now the two custom block created in block like

Now assign the blocks to region required region. i assigned the blocks to right slider bar it shows block content like

Thanks..

shan

Advertisements

From → Drupal

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: