views:

219

answers:

2

I have a custom module in Drupal that outputs a serialized dump of data. I want this page where the dump appears to not use the active theme. Instead, I just want the data dump to appear without any HTML markup, theme, JS, CSS, etc. Just the dump (another web site will be consuming it).

If I was doing this at the theme level I would simply create a new page.tpl.php file for a specific content type to appear without any theming, HTML, etc. But I need to do this at the module level for just this one page that the module creates as this module will be installed on different Drupal sites.

Is there a way to disable all theming and control the HTML wrapping output of a module page at the module level? All I really want to do is "turn it off", if this is even possible.

I'm running Drupal 6.

+6  A: 

Well it's a different approach, but one that always worked for me.

When your page callback is called in the module, instead of returning the data (which will theme it), just print or echo the data and do not return on the function.

Chris Ridenour
Exactly. Drupal core does the same, see http://api.drupal.org/api/function/upload_js/6 for instance.
marcvangend
Thanks, this worked great.
Justin
+3  A: 

For the given use case (output raw data for automated consumption), Chris answer is definitely the way to go (+1).

Just for completeness sake, and as an explicit answer to the question of replacing the page.tpl.php from within a module, one can also implement a moduleName_preprocess_page(&$variables) function. Within that function, $variables['template_files'] will contain an array of filename suggestions. The first one of those that matches an existing *.php.tpl file within the Drupal instance will be used as the page.tpl.php file for that request, so replacing the existing entries with e.g. 'moduleName_page.tpl.php' would cause that one to be used for theming the page.

Of course, one has to make sure that no other module manipulates the suggestions again afterward. Alternatively, one can also put the filename into $variables['template_file'] - this will be merged with $variables['template_files'] later on, but the 'template_file' entry will end up as the first.

Henrik Opel

related questions