I created a node type called "code". I created node-code.tpl.php. Contents this file:

print $node->content['body']['#value'];

I created a page template called page-code.tpl.php. (Note, I extended the templates array to check for aliases too, not the default $_GET['q']). Contents of this file:

if( arg(2) != 'edit': print $content;
else: 
/* fill in the usual template code */
endif;

I created a node with the path example.com/code/test-file-xml.

<?php
header("Content-type: text/xml; charset=UTF-8"); 
?>
/* xml code */

When I look at that page, the XML comes up correctly. However, I have a flash file loading on my front page that loads that flash file...and for whatever reason, the ENTIRE page is processed as an XML file??? Firefox loaded it but it was missing a few key things that caught my attention. IE doesn't load it at all, spit out that there's XML errors. That's when I realized the problem might be part recent creation.

So, i went back and commented out the header comment:

<?php
//header("Content-type: text/xml; charset=UTF-8"); 
?>
/* xml code */

...and all is well.

The bigger picture is I wanted to use node type "code" to do various other things. If you can see the application, you can see where I'm going with this.

So can anyone tell me why header() doesn't work inside drupal in this situation? I totally thought it should've but I guess I don't understand the way some of this Drupal builds the pages then....

Comments

yelvington’s picture

... does exactly what it's supposed to do. A Web page can only be of one content type. If you're putting XML inside a page container it's bound to conflict with the rest of the page.

xxparanormalxx’s picture

That I agree, header does exactly that. What I don't get is why it's called in that fashion. The goal as this:

Manage the XML file inside drupal and have drupal deliver it. The flash file on the front page that references example.com/xml/test-file.xml (an actual XML file) gets the same data as example.com/code/test-file-xml. I believe they're the same because when I put in these URL's, firebug spits back the same data and headers. The real major difference is the URL. So with that logic, I believed that my implementation would work...just referencing an "external" file. If anything, the header was already sent with the page load and then the flash requests that file, a different page load, so to speak.

So could you tell me or lead me to resources that explains how drupal's builds the pages? I thought what I knew how it worked (Drupal Pro Dev book) and hence tried this approach. It's clearly not working. =[

xxparanormalxx’s picture

I think I got it. In the process of building everything, THAT header is being called before ( again, obviously ) any other header that Drupal might be calling. That's such a bummer!!!