Embed a view:
<?php
$view = views_get_view('viewname');
print $view->execute_display('default', $args);
?>And to explain furthur, you can change ‘default’ to whatever display id you want (‘page_1′, ‘block_1′, ‘block_2′), eg.:
<?php
$view = views_get_view('viewname');
$display = $view->execute_display('block_1');
print $display['content'];
?>This is important if you want your embedded view to pick up any of your custom theming.
For reference, my snippet:
<?php
$url = explode('/', trim(request_uri(), '/'));
$url[0]= str_replace( '?q=', '', $url[0]);
$args = array($url[1]);
print views_embed_view('nodequeue_1', 'page', $url[1]);
?>Just another way of doing it by creating a variable from template.php to embed a view in template files or through php filter. You can now use vars['embed_rooms_view_1'] anywhere as $embed_rooms_view_1. The js is rebuilt using drupal_get_js() to overcome an issue with if you are using views slideshow then to load the js in preprocess function.
<?php
function themename_preprocess_page(&$vars, $hook) {
$vars['embed_rooms_view_1'] = views_embed_view(‘rooms’, ‘block_1′);
$vars['embed_rooms_view_2'] = views_embed_view(‘rooms’, ‘block_2′);
$vars['scripts'] = drupal_get_js();
}
?>Tags: drupal, drupal snippets, embed views, views, views_embed_view, views_get_view
1 Comment → Leave a Reply

Im usualy doing like this:
$arg0 = arg(0);
print view_embed_view(‘view_name’, ‘view_display_name’, arg0);
And execute method is only in case I have to chage view settings instead of using default;