sending arguments to block View in the tpl file
I have a block View that is displayed like so in my page.tpl.php file:
<?php if (!empty($subslider)): ?>
<div id="subslider">
<?php print $subslider; ?>
</div>
<?php endif; ?>
In the View Ui I set this default php argument:
$url = explode('/',$_GET['q']);
$slideshow = node_load($url[1]);
if($slideshow->field_slide_ref[0]['nid']){
return $slideshow->field_slide_ref[0]['nid'];
}else{
return '';
}
It grabs the reference id set in the page node.
Now, my problem is that im using page.tpl.php for other types of content that aren't necessarily nodes with a reference id in 开发者_JAVA技巧the url. I still want to pass an argument to the block View though. How do I do this in my template file?
Thanks
EDIT:
subslider is a block region. Im using Views Slideshow to make a slideshow.
I dont think I can use views_get_view_result because that just retrieves an array.. I need the actual slideshow.
In my comment, I mentioned views_embed_view(), which is different than views_get_view().
$slideshow = views_embed_view('my_slideshow_view', 'block_1', arg(1));
Also note, you don't need to explode $_GET['q']. You should be able to access URL arguments with: arg(0), arg(1), arg(2), etc....
I battled with this for a while. If you use view_embed_view()
then you should read http://drupal.org/node/823056 at it explains what you have to do to make it work for a views_slideshow.
Another solution is to use JQuery. First you add the views_slideshow block to your content region. Then you create a div container on the page <div id="my-rotator"> </div>
where you want it to appear (i.e. edit the node)
Then in your page.tpl.php add the following script but you'll need to replace block-views-my_image_rotator-block_2
with the name of your views block - find it by using Firebug:
<script type="text/javascript">
$(document).ready( function(){
var oNewContainer = $("div#my-rotator");
var oRotator = $("div#block-views-my_image_rotator-block_2");
oNewContainer.append(oRotator);
});
</script>
PS. You can control on what page the views-slideshow appears by configuring the block
精彩评论