I would like to display a Drupal view without the page template that normally surrounds it - I want just the plain HTML content of the view's nodes.
This view would be included in another, non-Drupal site.
I expect to have to do this with a number of views, so a solution that lets me set these up rapidly and easily would be the best - I'd prefer not to have to create a .tpl.php file every time I need to include a view somewhere.
there are probably a number of ways around this, however, the "easiest" may be just setting your own custom theme, and having the page.tpl.php just be empty, or some random divs
this method would basically just allow node.tpl.php to show (or any of drupal's form views, etc...) and would be an easy way to avoid modifying core, or having to alter the theme registry to avoid displaying page.tpl.php in the first place.
edit: see comments
ok i played around with views a bit, it looks like it takes over and constructs it's own "node.tpl.php" (in a sense) for display within "page.tpl.php". on first glance, my gut feeling would be to hook into
theme_registry_alter()
.when you're looking at a views page, you have access to piles of information here, as well as the page.tpl.php paths/files. as such i would do something like:
this should allow you to use a "override_page.tpl.php" template in your current theme in which you can remove anything you want (as my first answer above).
a few things:
views_ui_list_views
is always available to check against, but it sounds like it should be set if we're looking at a viewtheme paths
of thepage
array if you prefer (to change the location of where drupal will look for page.tpl.php, instead of renaming it altogether)template_preprocess_page()
might be a better idea.Another way to do it which I find very handy is to add a menu item with a page callback function that doesn't return a string:
Example:
-- Update
It would be much better to use
exit();
instead ofreturn TRUE;
(see comment).Hey, here's yet another way of doing it:
1) Download and install Views Bonus Pack (http://drupal.org/project/views_bonus) 2) Create a Views display "Feed" and use style "XML" (or something you think fits your needs better). 3) If you're not satisfied with the standard XML output, you can change it by adjusting the template for the view. Check the "theme" settings to get suggestions for alternative template names for this specific view (so you'll still have the default XML output left for future use).
Good luck! //Johan Falk, NodeOne, Sweden
jeroen's answer was what did for me after playing with it. I have a Drupal 7 site.
First of all make sure you replace
MY_THEME
with your theme name. Yes it is obvious but most newbies miss this.I actually already had a
function MY_THEME_preprocess_page(&$variables) {
. Do not recreate the function then but add this code at the end of the function before you close it with}
.$vars
not$variables
, so I had to update that as well. Again obvious if you think look for it.Based on answer of Philadelphia Web Design (thanks) and some googling (http://drupal.org/node/957250) here is what worked for me in Drupal 7 to get chosen pages displayed without the template:
instead of phptemplate, in D7 there has to be the name_of_your_theme in the name of the function. Also, I had to put two underscores __ in the php variable with the file name, but the actual template file name needs two dashes --
content of page--vlozeno.tpl.php :
The output, however, still has got a lot of wrapping and theme's CSS references. Not sure how to output totally unthemed data...
There is also http://drupal.org/project/pagearray which is a general solution...
Also, @Scott Evernden's solution is a cross site scripting (XSS) security hole. Don't do that. Read the documentation on drupal.org about how to Handle Text in a Secure Fashion http://drupal.org/node/28984