Create Block via module in Drupal

For creating block via code you need to  call block hook.
function <modulename>_block($op = 'list', $delta = 0) {
    $block = array();
    if($op == 'list') {

        $block[1]["info"] = t(ucfirst('First Block'));
        $block[2]["info"] = t(ucfirst('Second Block'));

    } else if ($op == 'view') {
        switch ($delta) {
        case 1:

            $block['subject'] = ucfirst('First Block');
            $block['content'] = 'Hello World this is 1st Block';
            break;
        case 2:
            $block['subject'] = ucfirst('Second Block);
            $block['content'] = 'Hellow World this is 2nd Block';

            break;

        }
    }
    return $block;
  }

 

 

 

Tags: 
X