Using views_embed_view()
Last updated on
7 March 2017
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
Problem:
The slideshow doesn't work when using views_embed_view in tpl.php
Why:
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.
Solution:
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.
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion