Simple, powerful, beautiful websites.

Rendering a View from code in Drupal 6

March 2, 2010

This is the type of thing that is I always forget how to do, so I figured it would make a good blog post, both for me, and for anyone else searching for this info online.

Here is the situation: I’ve got a page in Drupal that I am rendering from code for some reason (in my current case, I’m using theme files to alter the output of a View, and I want to include another View within each row). It sure would be nice to know how to load up and display a View within my code. Here is how:


$view_args = array(); // place any arguments here
$display_id = 'panel_pane_1'; // the name of the display to load
$view = views_get_view('view_name'); // get our view
if (!empty($view)) {
$content = $view->execute_display($display_id, $view_args);
print $content['content'];
}
?>

Nice! Now the view will show up just where I want it! If you have questions, post a comment!

Leave a Reply