Monday, 3 October 2011

simple drupal "hello world" block custom modules


this is just a really fast and crude way to printout the content in creating a drupal custom modules

 module name "hello_world"

first step is to create a "info" file for your modules ""

and paste in the before code

 ; $Id$  
 name = hello_world  
 description = Custom functions for this site.  
 core = 6.x  

next step is to create a module file this is the file where all the logic goes
create a file "hello_world.module" and paste in the below code

 // $Id: hello_world.module  
 * @file* Custom functions for this site.  
  //implementing the hook_block functions   
 function hello_world_block($op = 'list',$delta = 0, $edit =array()){  
 if($op == 'list'){ //listing the blocks  
 'info'=> t('hello world block'),  
 'weight' => 0,  
 return $blocks;  
 //loading the content of the blocks   
 if($op == 'view'){  
 if($delta == 0){  
 $blocks = array(  
 'subject' => t('hello world blocks'),  
 'content' => '<h1>hello world</h1>';// alternatively you can call a function which return the data  
 return $blocks;  

this above code can be used to quickly create block to display a banner or ad-script in a block or a even iframe.

No comments:

Post a Comment