Monday, January 31, 2011

How to create a block using module in Drupal 6.



Custom Drupal module | Code for building block using Drupal custom module
By using this piece of code you can easily create a block that can display anything. If you want to show data for a particular content  type or anything from database this code will be very helpful for that.

Suppose your custom module name is xyz.
<?php
function xyz_block($op='list', $delta=0, $edit = array())
{

    if( $op == 'list' ) {
             $block[0]['info'] = "Test";
                         
             
    } else if ( $op == 'view' ) {
            switch($delta) 
            {
                 case 0:
                         $block['subject'] =  "Test";
                         $block['content'] =  xyz_Services();
                         break;
            }
     }
                         
     return $block;
}


function xyz_Services()
{  
    … PUT YOUR CODE HERE  FOR OUTPUT [BLOCK CONTENT]…
}
?>

No comments:

Post a Comment