Creating Feeds

Events happening in the community are now at Drupal community events on www.drupal.org.
jredding's picture

Quick question...

I have a PHP Page that outputs XML but its theming it within PHPTemplate.

So.. umm. .how do I prevent ALL theme output?

Comments

easy

moshe weitzman's picture

don't call theme('page'). just print your output and then return empty string or NULL (i can't recall) from your menu callback

Thanks but...

jredding's picture

Wouldn't this require altering my theme so that theme('page') isn't called? Is it possible to do this if you are using a standard Page node and selecting PHP Code as the input format?
i.e.
create content-->Page
Type in php code
Select Input Format "PHP Code"

Hit Submit?

Or do I need to create a CCK Type named something like "PHP Code Feeds", then create a template file content-php_code_feeds.tpl.php and prevent the theme('page') call from the template file?

Now that I think of it.. I don't think this is possible.. Drat! but... maybe???

-Jacob Redding

-Jacob Redding

Hacks

Anonymous's picture

I've hit this before. Here are some not-pretty hacks; I've used both of these:

(1) Set the headers yourself using php, e.g.,:

<?php
header
("Content-type: text/xml; charset=UTF-8");
print
"<?xml blah blah blah
?>
"; //I do this so the <? isn't interpretted as php
?>
the rest of your XML here
<?php
exit;
?>

(2) Set up a vocabulary for "special themes." In your template.php, check the taxonomy term for "XML output" and short-circuit the normal themeing and just dump the body wrapped in the appropriate whatever...

That was me... Sorry about

strudeau's picture

That was me...

Sorry about the code formatting. WTF? Anyway, should be readable.

I should also say that if

strudeau's picture

I should also say that if you take the "set the headers and exit" approach, I highly recommend adding some kind of wrapper around it to make sure you can access the node when logged in as admin. I've done this one of two ways:

(1) Check to see if the user is in an "admin" (or other) role and if so, do not actually dump the output (this requires you to use a different browser or log out to test)

(2) Look for a $_GET variable and only intercept headers when this variable is set; fix links accordingly

What about CCK types?

jredding's picture

Instead of setting up a taxonomy could I use a CCK Type and check for the type?

Also maybe I'm tired or overworked but how exactly do I check for this with template.php? What function do I override?

-Jacob Redding

-Jacob Redding