displaying a Drupal view without a page template around it

ceejayoz picture ceejayoz · Oct 29, 2008 · Viewed 49.1k times · Source

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.

Answer

Philadelphia Web Design picture Philadelphia Web Design · Mar 4, 2009

I was looking for a way to pull node data via ajax and came up with the following solution for Drupal 6. After implementing the changes below, if you add ajax=1 in the URL (e.g. mysite.com/node/1?ajax=1), you'll get just the content and no page layout.

in the template.php file for your theme:

function phptemplate_preprocess_page(&$vars) {

  if ( isset($_GET['ajax']) && $_GET['ajax'] == 1 ) {
        $vars['template_file'] = 'page-ajax';
  }

}

then create page-ajax.tpl.php in your theme directory with this content:

<?php print $content; ?>