tags:

views:

186

answers:

2

Hi,

I have a drupal module with a function that returns an attachment text/plain,

function mymodule_menu() {
$items = array();
$items[MY_PATH] = array(
'title' => 'some page',
'page callback' => 'myfunction',
'type' => MENU_CALLBACK,
);
}

function myfunction()
{
drupal_set_header('Content-Type: text/plain');
return "some text";
}

But it returns the page in the page.tpl.php template, however I want it untemplated, how do I over-ride the theme to make it return plain text?

Thanks,

Tom

A: 

Your module can define template files (reference):

<?php
function mymodul_preprocess_page(&$variables) {
     foreach ($variables['template_files'] as $file) {
     $template_files[] = $file;
     if ($file == 'page-node') {
        $template_files[] = 'page-'. $variables['node']->type;  
     }
    }
   $variables['template_files'] = $template_files;
}
?>

By creating a new .tpl.php file for the page in question. E.g.

page-module.tpl.php

page-module.tpl.php would only need to be a simple page, e.g.

<?php
print $content;
?>
wiifm
Hi, thanks!The text file is not a content type, its a report generated from php/database so I'm am not sure I get what you mean.However I have just realised, that if I do print "whateever";and not return "whatever";drupal doesn't display the page template. I would still be interested to know how you would get drupal to apply the page-plain.tpl.php template to arbitrary content...
Tom
+4  A: 

This will return plain text

function myfunction() {
  drupal_set_header('Content-Type: text/plain');
  print "some text";
  exit(0);
}
Jeremy French
+1 - This is the way Drupal itself returns 'unthemed' content, e.g. answers to js callbacks or files (when private files are enabled). See the http://api.drupal.org/api/function/file_transfer/6 for an example of this in core.
Henrik Opel
A word of warning applies: When ending the normal Drupal request processing via exit()/die(), *hook_exit will not be invoked*, so make sure not to rely on that in these cases.
Henrik Opel

related questions