How to call VR block manually?
szy - January 7, 2009 - 03:08
| Project: | Views Rotator |
| Version: | 6.x-1.0-alpha2 |
| Component: | Documentation |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
| Issue tags: | module_invoke, views, Views Rotator |
Jump to:
Description
Hi there,
I was trying to call Views Rotator's block manually, according to Placing the contents
of a block in any location - but it doesn't work:
<?php
$block = module_invoke('views_rotator', 'block', 'view', 0);
print $block['content'];
?>So, what works? :]
Szy.

#1
According to my research, invoking the block doesn't work with views. You have to embed it. However, I tried two methods and neither succesfully loaded the rotator. Just a normal view.
This topic [http://drupal.org/node/309017] supposedly has a solution for D5 users.
If someone could 'translate' this fix to D6/Views2, I would be extremely grateful!
#2
You are looking at embedding it directly into a page? Like a page.tpl.php file?
If that's the case you want to use views_embed_view to embed it. Now, you don't want to call this directly in your template.php files. This will add JavaScript to a page and if the JS is already added to the header it can't be altered.
So, what you need to do is have a template.php file. In there have something like.
<?phpfunction phptemplate_preprocess_page(&$vars) {
$vars['my_embedded_view'] = views_embed_view('my_view');
$vars['scripts'] = drupal_get_js(); // This rebuilds the scripts variable with those added by the view
}
?>
Then in your page.tpl.php file place the $my_embedded_view variable where you want the view.
#3
Thank you for your reply.
I am a bit confused though about how exactly this 'phptemplate_preprocess_page' function works.
The argument passed (&$vars) is a pointer to an array with multiple views, but the 'views_embed_view' function will only return the
'my_view' content and places it on the 'my_embedded_view' position.
It is not clear to me how this would generate content with embedded javascript.
Could you clarify the usage of this function with a simple call and print example?
#4
My working solution for two different rotated views, thanks to mfer! :]
In template.php:
function my-theme_preprocess_page(&$vars) {$vars['my_rotated_view'] = views_embed_view('my_rotated_view');
$vars['my_another_rotated_view_on_front'] = views_embed_view('my_another_rotated_view_on_front');
$vars['scripts'] = drupal_get_js();
}
... where my_rotated_view and my_another_rotated_view_on_front are names
of my views build with Views Rotator style.
Then in page.tpl.php in place where I want to see the view:
<?php print $my_rotated_view; ?>... and in page-front.tpl.php:
<?php print $my_another_rotated_view_on_front; ?>More - in mycustomnode-node.tpl.php:
<?php if ($view->name == 'my_rotated_view'): ?>
<div class="...
[here comes your custom template for this node type in this particular view]
<?php endif; ?>
Szy.
#5
Hmm its not working in my case. I edited my template.php with the following lines
function phptemplate_preprocess_page(&$vars) {$vars['imagerotatortest'] = views_embed_view('imagerotatortest');
$vars['scripts'] = drupal_get_js();
}
<?php print $imagerotatortest; ?>in page-front.tpl.php but nothing is showing on the frontpage. "imagerotatortest" is the name of my view containing the views rotator design.Any suggestions how to make it work?