1

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 --> page callback function --> custom theme function --> hook_theme implementation --> .tpl.php template file

what I would like it to do:

hook_menu --> page callback function --> return a <div> to be displayed on its own

Can anyone help?

1 Answer 1

4

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();
}
1
  • exit()/drupal_exit() is not necessary. If you do not return anything from a page callback, then Drupal will not render anything additional but still call the proper hooks and so on.
    – Berdir
    Commented Jun 4, 2011 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.