Instead of returning the string you want to use as output, print it using code similar to the following one.
print $output;
module_invoke_all('exit');
exit();
$output
is the variable containing the output you want to show.
While the module_invoke_all('exit')
call is not strictly necessary, it notifies other modules that Drupal is terminating. There are modules that implement hook_exit() to do their job, and they will not work, without that call; their purpose is to write something in a Drupal variable, or in a database table, and they don't interfere with the output your are producing.
The reason why it is necessary to do this is the code used by index.php, which contains the following:
$return = menu_execute_active_handler();
// Menu status constants are integers; page content is a string.
if (is_int($return)) {
switch ($return) {
case MENU_NOT_FOUND:
drupal_not_found();
break;
case MENU_ACCESS_DENIED:
drupal_access_denied();
break;
case MENU_SITE_OFFLINE:
drupal_site_offline();
break;
}
}
elseif (isset($return)) {
// Print any value (including an empty string) except NULL or undefined:
print theme('page', $return);
}
drupal_page_footer();
If you return a string, it is passed to theme('page')
, which renders the page as you are noticing; if you return nothing, then both is_int($return)
and isset($return)
are FALSE
, and the relative code is not executed.
The equivalent for Drupal 7 for the code I wrote for Drupal 6 would be the following one:
print $output;
drupal_exit();
drupal_exit() contains already the call to module_invoke_all('exit')
.