Using views_embed_view()

Last updated on
7 March 2017


The slideshow doesn't work when using views_embed_view in tpl.php


When you use views_embed_view in your tpl.php file the javascript has already been rendered for the page so the necessary javascript for views_slideshow isn't loaded on the page.


In your theme's template.php add:

function mythemename_preprocess_page(&$vars, $hook) {
  // Render the view.
  $vars['embedded_view'] = views_embed_view('page_image_rotator', 'block_1');
  //Reload the javascript into the scripts.
  $vars['scripts'] = drupal_get_js();

In the tpl.php file where you are embedding the view put:

  <?php print $embedded_view; ?>

Thank you to aaron.r.carlton for this solution.