Hi!
I'm making my first module - it parses drupal nodes to xml for flash interfacing.
My problem is:

I'm making a page with hook_menu, but i don't want the page to include drupal templates like page.tpl.php. I want it to render the page as xml and need it to start th page with

 $xml_header='<?xml version="1.0" encoding="UTF-8"?>';
header('Content-type: text/xml');
print $xml_header; 

I can do this by altering på page.tpl.php, but I would like my module to do this automatically.
How? :)

Comments

asund’s picture

maybe i should be more clear:

I'm making the page /xml_parser with hook_menu in my module.
I want drupal to drop the page.tpl.php when on this path (or use another template file in the module directory).
I don't want to have to change to theme templates to do this.. :)

mikeschinkel’s picture

If you are using hook_menu, you specify what function is called and in that function you don't have to call the functions that ultimate call page.tpl.php. Or maybe I'm missing something?

Can you give some more details on what you are trying to accomplish complete with example URLs and what you want them to do, and why?

asund’s picture

if i use print $output; in stead of return $output; it overrides the template, but is that good practice?

mikeschinkel’s picture

That's not what I was asking.

What is your business use-case?

What are your URLs that you plan to use?

Do you want an XML URL for each content node, or something else?

I guess I don't understand what you are trying to do and I need to understand to offer help.

mikeschinkel’s picture

DUPLICATE POST

bkildow’s picture

I just had a similar problem. I wanted to create a template with just html markup, and not have it run through the default page.tpl.php. Here is what I did in my module:

function mymodule_menu() {
  $items = array();

  $items['my-special-page'] = array(
    'title' => 'This is my custom page',
    'page callback' => 'my_special_page',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}

function my_special_page() {
  return theme('my_special_page');
}

function mymodule_theme($existing, $type, $theme, $path) {
  return array(
    'my_special_page' => array(
      'arguments' => array('options' => NULL),
      'template'  => 'page-my-special-page',
    ),
  );
}

function mymodule_theme_registry_alter(&$theme_registry) {
  $theme_hook = 'page'; // my hook name
  // Get the path to this module
  $modulepath = drupal_get_path('module', 'mymodule');
  // Add the module path on top in the array of paths
  array_unshift($theme_registry[$theme_hook]['theme paths'], $modulepath);
}

And then I created a page template called page-my-special-page.tpl.php in the mymodule folder. The code in mymodule_theme_registry_alter adds your module path to the top of the suggested files. By naming your template page-something.tpl.php you are overriding the default page.tpl.php.

I hope that helps!