How do I return the output from a callback function unthemed? I have a custom module with a hook_menu() "page callback" function, a custom theme function and a hook_theme() implementation. This module is working fine and the final output of the module is passed to the template of my site.

However, what I would like to do is to have the output of the module to be displayed on its very own - nothing else. That is:

what it does now:

hook_menu --&gt; page callback function --&gt; custom theme function --&gt; hook_theme implementation --&gt; .tpl.php template file


what I would like it to do:

hook_menu --&gt; page callback function --&gt; return a &lt;div&gt; to be displayed on its own


Can anyone help?
This is really easy: instead of returning the output in the page callback, just print it and exit.

Drupal 6

function foo_callback() {
  print theme('foo');
  exit();
}


One thing to keep in mind when doing this is that hook_exit() will not be invoked, as you'll be ending the script before Drupal reaches that point, so make sure you don't need it. If you do, you can invoke it yourself before calling exit():

function foo_callback() {
  print theme('foo');
  module_invoke_all('exit');
  exit();
}


Drupal 7

drupal_exit() was added for this use-case, and will call all the shutdown stuff before exiting. So you just need:

function foo_callback() {
  print theme('foo');
  drupal_exit();
}