Skip to main content

How to display a Drupal view using PHP

Submitted by amitsedai on
The following code snippet displays the view: <?php $view = views_get_view('view_name'); //output the view print $view->execute_display('page_1'); //page tab id ?> To display the view elsewhere. Fox ex: Mailing the view result data. <?php $view_name = 'view name'; $display_id = 'display id'; $view = views_get_view($view_name); if ( is_object($view) ) { $view->set_display($display_id); $view->pre_execute(); return $view->render($display_id); } ?> Also another way: <?php return views_embed_view('view_name', 'display_id') ; ?> -- Links: https://www.drupal.org/node/951442#comment-3619322

Technologies