/ Published in: PHP
                    
                                        
This is a hook_block_info and hook_block_view template that will allow you to quickly create blocks in a Drupal module. When you use this all you have to do is create a directory "blocks" in the module and then create block.block_name.php in the directory. Inside the php you need to define a function block_block_name_content().
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
<?php
/**
* @file
* This file defines the robmod module.
*/
/**
* Implements hook_block_info().
*/
function robmod_block_info() {
// Get the module name
// Build a glob to get all the blocks defined.
$module_path = drupal_get_path("module", $module);
$block_path = $module_path . "/" . "blocks";
// The empty block info array.
foreach($block_files as $file) {
// Block name
$block = $matches[1];
// Name can be translated why not?
$r[$block]['info'] = t($block_name);
// Assume no cache.
$r[$block]['cache'] = DRUPAL_NO_CACHE;
}
}
return $r;
}
/**
* Implements hook_block_view().
*/
function robmod_block_view($delta = '') {
// Get the module name
// Setup a blank block.
$block['subject'] = t($delta);
$block['content'] = t('No Content Defiend for: ') . $delta;
// Build a path to the block file.
$module_path = drupal_get_path("module", $module);
$block_path = $module_path . "/" . "blocks";
$block_file = $block_path . "/" . "block." . $delta . ".php";
// Does the file exists?
// Yes it does so let's include it.
include_once($block_file);
// We should now have a function from that.
$function = "block_".$delta."_content";
// Does that function exist?
// Yes assign the return to the block content.
$block['content'] = $function();
}
}
return $block;
}
URL: http://www.itsgotto.be/cv.php
Comments
 Subscribe to comments
                    Subscribe to comments
                
                