This is my first try to create a Drupal module: Hello World.
I need it to have it displayed as a custom block and I found this can be implemented by 2 Drupal7 hooks: hook_block_info() and hook_block_view() inside my my helloworld module. In Drupal 6 was used the deprecated hook_block().
In the actual form it works but it only display the text: 'This is a block which is My Module'. I actually need to display the output of my main function: helloworld_output(), the t variable.
<?php
function helloworld_menu(){
$items = array();
//this is the url item
$items['helloworlds'] = array(
'title' => t('Hello world'),
//sets the callback, we call it down
'page callback' => 'helloworld_output',
//without this you get access denied
'access arguments' => array('access content'),
);
return $items;
}
/*
* Display output...this is the callback edited up
*/
function helloworld_output() {
header('Content-type: text/plain; charset=UTF-8');
header('Content-Disposition: inline');
$h = 'hellosworld';
return $h;
}
/*
* We need the following 2 functions: hook_block_info() and _block_view() hooks to create a new block where to display the output. These are 2 news functions in Drupal 7 since hook_block() is deprecated.
*/
function helloworld_block_info() {
$blocks = array();
$blocks['info'] = array(
'info' => t('My Module block')
);
return $blocks;
}
/*delta si used as a identifier in case you create multiple blocks from your module.*/
function helloworld_block_view($delta = ''){
$block = array();
$block['subject'] = "My Module";
$block['content'] = "This is a block which is My Module";
/*$block['content'] = $h;*/
return $block;
}
?>
All I need now is to display the content of my main function output: helloworld_output() inside the block: helloworld_block_view().
Do you have an idea why $block['content'] = $h won't work? Thanks for help.