i created a view with a slide show (for page and default display).
i don't see the slide show in the preview (view edit).
if i create a page and visit the url with the browser i see the slide show.
if i embed a view in a page with views_embed_view() i don't see the slide show.

is this a normal behavior or can i do something about it?

cheers.

Comments

dragonwize’s picture

Title: views_embed_view() with slideshow » views_embed_view does not work
Category: support » bug

The slideshow will never work in the preview. This is because of how views does previews not any fault of this module. Views just pulls the data it doesn't do full theming which would include the needed javascript.

The views embed doesn't currently work but hopefully will be fixed in a future release.

e_log’s picture

thanks for the clarification!

sebos69’s picture

Hi,

I just tried the Views Slideshow module (-dev version), within an views_embed_view(), and the slideshow actually displays and refreshes itself, but below the slideshow, I get extra-caracters like:

<!--close views_slideshow_div_1_1-->
<!--close views_slideshow_div_1_2-->
<!--close views_slideshow_div_1_3-->
<!--close views_slideshow_div_1_4-->
<!--close views_slideshow_no_display-->
<!--close views_slideshow_main_1-->
redndahead’s picture

Version: 6.x-1.0-beta1 » 6.x-2.x-dev
Status: Active » Postponed (maintainer needs more info)

Hmm seems like a tag isn't closed. I know it's been a long time has this been fixed sebos69?

redndahead’s picture

Status: Postponed (maintainer needs more info) » Fixed

Marking as fixed. Feel free to reopen if you still have problems.

jboeger’s picture

Can we re-open this please? I am having the same problem:

redndahead’s picture

Status: Fixed » Postponed (maintainer needs more info)

I'm assuming your problem is with view_embed_view. If that's the case can you see if the js files get loaded on that page.

redndahead’s picture

Status: Postponed (maintainer needs more info) » Fixed

Closing from lack or response.

burlinwall’s picture

I am having the same problem. No js gets loaded when using views_embed_view. If i hard code the necessary js, it works, obviously.

burlinwall’s picture

This was marked as fixed, but is it really? still doesn't work.

jfox77’s picture

I am also having this problem:
Using views_embed_view() in my page.tpl.php file to display a view that has a style of "Slideshow" does not work. The first image appears but they never rotate.

I added these lines to the top of my page.tpl.php but that didn't help.

<script type="text/javascript" src="/sites/all/modules/views_slideshow/js/views_slideshow.js"></script>
<script type="text/javascript" src="/sites/all/modules/views_slideshow/js/jquery.cycle.all.min.js"></script>

If I use the views_embed_view call in the body of one of my pages it works. But not when I put it in my page.tpl.php file. What else do I need to add to page.tpl.php so that it executes the same way it does as when it's in the body of a drupal page?

print views_embed_view('Courthouses',$display_id = 'Page');

Thanks!!

burlinwall’s picture

You have added the necessary files but your are missing the settings. For example, the code below is what loads in to my page in addition to the files you mentioned (when not using the embed function). If i hard code this into my page template, it works, but that's certainly not the way to go.

<script type="text/javascript"> 
<!--//--><![CDATA[//><!--
jQuery.extend(Drupal.settings, { "viewsSlideshowSingleFrame": { "#views_slideshow_singleframe_main_1": { "num_divs": 5, "hoverFunction": null, "id_prefix": "#views_slideshow_singleframe_main_", "div_prefix": "#views_slideshow_singleframe_div_", "id": 1, "timeout": "4000", "sort": 1, "effect": "fade", "speed": "400", "cleartype": "t", "cleartypenobg": "f", "delay": "0", "random": "0", "pause": "2", "controls": "0", "pager": "0", "pager_type": "0", "pager_hover": "2", "image_count": "0", "sync": "1", "advanced": "", "ie": { "cleartype": "true", "cleartypenobg": "false" } } } });
//--><!]]>
</script> 
jfox77’s picture

I added that section of code and now it's acting like it's trying to work, but it is just alternating between my first image and then no image. My second image is never appearing. What else am I missing?

Thanks!

jfox77’s picture

Ok, so after spending quite a bit of time on this, here's what finally worked for me:

1. put this in a block:

<?print views_embed_view('Courthouses');?>

2. Assign the block to a region (i.e. header_last)

3. put this in my page.tpl.php

<?php print $header_last; ?>

4. In my views settings:
Style = Slideshow
Items to display = 12 (I have 12 images)
Filters = filter by content type since I have a specific content type of "Courthouses" that allows an image to be attached.
Filters = add filter to make sure the content type actually has an image attached

burlinwall’s picture

jfox77, you can´t use my code. that is specific for when i generated my view. it was just an example.

jstoller’s picture

Category: bug » support
Status: Fixed » Active

If views_embed_view() isn't going to work, than can someone please recomend an alternative method?I was hoping to have a function I could asign to a variable in template.php, and print in page.tpl.php to display the view slideshow.

titouille’s picture

My two cents :

I have a slideshow block view to add on all pages of my site, in the footer.

in template.php, outside any function :

  $base = drupal_get_path('module', 'views_slideshow_singleframe');
  drupal_add_js($base . '/views_slideshow.js', 'module');
  drupal_add_css($base . '/views_slideshow.css', 'module');
  if (module_exists('jq')) {
    if (in_array('cycle', jq_plugins())) {
      $js = jq_add('cycle');
    }
  }

  // Otherwise, we'll add the version included with this module.
  if (!$js) {
    drupal_add_js(drupal_get_path('module', 'views_slideshow') .'/js/jquery.cycle.all.min.js', 'module');
  }

(code from module...)

I have two functions to retrieve the jQuery.extend() content, parse it and add a new slideshow element to get my block working :

function override_jQueryExtend_script( $scripts, $domid )
{
	// create new slideshow element
	$slideshow = array(
			'num_divs' => 2,
			'hoverFunction' => null,
			'id_prefix' => '#views_slideshow_singleframe_main_',
			'div_prefix' => '#views_slideshow_singleframe_div_',
			'id' => $domid,
			'timeout' => 5000,
			'sort' => 1,
			'effect' => 'fade',
			'speed' => 700,
			'cleartype' => 't',
			'cleartypenobg' => 'f',
			'delay' => 0,
			'random' => 0,
			'pause' => 1,
			'controls' => 0,
			'pager' => 0,
			'pager_type' => 0,
			'pager_hover' => 2,
			'image_count' => 0,
			'sync' => 1,
			'advanced' => "",
			'ie' => array(
				'cleartype' => "true",
				'cleartypenobg' => "false" ) );

	// test if CDATA exists. if exists, it's already a "jQuery.extend( ... )" script.
	$startIndex = strpos( $scripts, "<!--//--><![CDATA[//><!--" );
	if( $startIndex )
	{
		$endIndex = strpos( $scripts, "//--><!]]>" );
		
		// retrieve content of method
		$extend = substr( $scripts, $startIndex + 25, $endIndex - ( $startIndex + 25) );
		$s = substr( $extend, 31, -3 );
		
		// decode content
		$result = json_decode2($s); 
		
		// add new slideshow element
		$result['viewsSlideshowSingleFrame']['#views_slideshow_singleframe_main_' . $domid] = $slideshow; 
		
		// re-encode content
		$json = json_encode( $result );
		$json = str_replace( ",", ", ", $json );
		$json = str_replace( ":", ": ", $json );
		
		$return = substr( $scripts, 0, $startIndex );
		$return .= "<!--//--><![CDATA[//><!--
jQuery.extend(Drupal.settings, {$json});
//--><!]]>";
		$return .= substr( $scripts, $endIndex + 10 );
	}
	else
	{
		$result = array();
		$result['viewsSlideshowSingleFrame']['#views_slideshow_singleframe_main_' . $domid] = $slideshow; 
		$json = json_encode( $result );
		$json = str_replace( ",", ", ", $json );
		$json = str_replace( ":", ": ", $json );
		$return = $scripts;
		$return .= "<script type=\"text/javascript\">
<!--//--><![CDATA[//><!--
jQuery.extend(Drupal.settings, {$json});
//--><!]]>
</script>";
		}
	return $return;
}
  
/*
 * method to decode json string
 * (not working with the json_decode php built-in function)
 */
function json_decode2($json) 
{  
    // Author: walidator.info 2009 
    $comment = false; 
    $out = '$x='; 
    
    for ($i=0; $i<strlen($json); $i++) 
    { 
        if (!$comment) 
        { 
            if ($json[$i] == '{')		$out .= ' array('; 
            else if ($json[$i] == '}')	$out .= ')'; 
            else if( $json[$i] == '[')  $out .= ' array(';
            else if( $json[$i] == ']')	$out .= ')';
            else if ($json[$i] == ':')	$out .= '=>'; 
            else						$out .= $json[$i];            
        } 
        else $out .= $json[$i]; 
        if ($json[$i] == '"')    $comment = !$comment; 
    } 
    eval($out . ';');
    return $x; 
}  

(yes, not really optimized code...)
Finally, in my [theme]_preprocess_page method, I just add the following lines :

	$sitesblock = views_embed_view('sites_list', 'block_sites_list');
	$index = strpos( $sitesblock, 'views_slideshow_singleframe_main_' );
	$domid = substr( $sitesblock, $index + 33, 1 );
  	$vars['scripts'] = override_jQueryExtend_script( $vars['scripts'], $domid );
	$vars['sitesblock'] = $sitesblock;
 

[edit]
Don't forget to call your new variable (called $sitesblock in my case) in the page.tpl.php, like
print $sitesblock;
[/edit]

And it works. Now the must would be to retrieve all settings of my block (timeout, effect, speed, etc...) and put it in the new array created in my override_jQueryExtend_script method but I don't know if it's possible.
I must search how to know the number of pictures stored in the block to pass it as "num_divs" setting. But it's a good start to get the slideshow working with views_embed_view method.
Any suggestion are welcome ;-)

psynaptic’s picture

Status: Active » Needs review

I committed a fix for this a couple days ago. Please test.

The View preview still doesn't work because views doesn't seem to fire template_preprocess_views_slideshow_[mode] which has the following code required for the slideshow to function:

$settings = array_merge(
    array(
      'num_divs' => sizeof($vars['rows']),
      'id_prefix' => '#views_slideshow_singleframe_main_',
      'div_prefix' => '#views_slideshow_singleframe_div_',
      'id' => $vars['id'],
    ),
    $options['singleframe']
  );
  drupal_add_js(array('viewsSlideshowSingleFrame' => array('#views_slideshow_singleframe_main_'. $vars['id'] => $settings)), 'setting');

Not sure what to do about this. Does anyone have any ideas?

redndahead’s picture

Priority: Normal » Critical

marking as critical to look at before release.

redndahead’s picture

Status: Needs review » Fixed

I'm marking as fixed. If people would like to see preview working please open a new issue.

dlx’s picture

Status: Fixed » Active

Hi redndahead,

I think whether preview is working or not really a non-issue here. The problem is that when views_embed_view() is called somewhere (not in the preview), the slideshow is not working.

Sincerely,
Alex

psynaptic’s picture

Are you trying with the latest dev?

redndahead’s picture

Status: Active » Postponed (maintainer needs more info)
aaron.r.carlton’s picture

I am also experiencing this issue. When I try to put the slideshow view in my page.tpl.php by calling views_embed_view(), the first frame renders but the slideshow does not initialize. I originally built my view using the 6.x-2.0 version but then replaced that with the 6.x-2.x-dev version and it still doesn't work. I am not at all concerned with whether the Views' preview functionality is working, this is broken when I try to render the view on the frontend.

Please elaborate on exactly which additional information you need to move this issue from postponed to the active list. I'll do my best to explain my scenario.

redndahead’s picture

Anyone have a website to look at?

Lloyd’s picture

Development site. I've included the embed code only within the content and it's not coming up.

http://205.186.128.246/life-insurance-brokerage

redndahead’s picture

If you don't use slideshow style and use unformatted style does it show up?

Lloyd’s picture

Yes it does. There are about 30 different nodes included in the view and using the unformatted style they all display (one per row). And when using the slideshow style, I used all of the default settings.

Lloyd’s picture

Ok that's odd. After I changed it from slideshow to unformatted, and then back to slideshow (without making any changes to settings), the slideshow is now displaying correctly.

redijedi’s picture

I am also experiencing this issue. Both with 6.x-2.0 and -dev. I get the following javascript error:

Error: Drupal.settings.viewsSlideshowSingleFrame is undefined
Source File: http://localhost/sites/all/modules/views_slideshow/contrib/views_slidesh...
Line: 14

It works fine when using a block. But embedding the view does not work.

aaron.r.carlton’s picture

Myself and a co-worker have been tracking this down. From what we can see, psynaptic's comment in #12 is closest to the issue. The problem is that drupal_add_js() is called deep inside the slideshow module in function template_preprocess_views_slideshow_singleframe().

Since I am trying to call views_embed_view() inside my theme's preprocess_page() function, the $scripts array has already been built, and the drupal_add_js() call to insert the slideshow settings onto the page never gets processed into $vars['scripts']. A workaround is to do something like this:

function mythemename_preprocess_page(&$vars, $hook) {
  $vars['embedded_view'] = views_embed_view('page_image_rotator', 'block_1');
  $vars['scripts'] = drupal_get_js();
}

rebuilding the $scripts variable processes the settings code back onto the page. While this should work in the meantime, I think the module should make sure its javascript gets onto the page in any situation. I've toyed around with the module, but can't figure out a really good strategy to do this. If anyone has suggestions, I will try to implement them and submit a patch.

Lloyd’s picture

I'm once again having problems. Things were working fine. I did an update to the css file, refreshed the page and now the block does not advance past the first image. In fact, I have another views slideshow block on this page (placed on the page using the traditional block functions) and that doesn't work either. If I remove the embedded block, the other one works. Put the embedded block back in, neither works.

And also, just like before I went back into Views and made a change, saved it, and the slideshow is now back to working.

redndahead’s picture

Status: Postponed (maintainer needs more info) » Active
redndahead’s picture

Status: Active » Postponed (maintainer needs more info)

Try using the latest dev. There are some rendering fixes that may help.

redndahead’s picture

Status: Postponed (maintainer needs more info) » Fixed

I think aaron.r.carlton has the correct solution. You need to add the embed into the preprocess function and reload the javascript. It's going to be a hazard of embedding the view. Any other action I take to try and make it work will require me to load it on every page not something I want. So let me recap on what to do.

In template.php have.

function mythemename_preprocess_page(&$vars, $hook) {
  $vars['embedded_view'] = views_embed_view('page_image_rotator', 'block_1');
  $vars['scripts'] = drupal_get_js();
}

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

<?php print $embedded_view; ?>

Sorry that there isn't a better solution.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

viil’s picture

Component: Miscellaneous » SingleFrame
Status: Closed (fixed) » Needs work

subscribing in case this will be looked into...

nravens’s picture

The solution mentioned in #35 worked for me but only in firefox... it doesn't seem to work in IE6... anyone know why that could be??

nravens’s picture

ok, I had a dumbass moment.. it's working. I forgot to enable the permissions for the content field. I was logged in as admin on firefox but not logged in on IE...

redndahead’s picture

Status: Needs work » Closed (fixed)

This should have stayed fixed.

mattwmc’s picture

I'm having difficulty embeding in front page using advanced front page settings mod.

<?php
$view = views_get_view('slideshow);
print $view->execute_display('default', $args);
?>

I guess I need to hardcode the javascript? Like in #11 and #12?

opensense’s picture

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();
}
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();
}

jameswoods’s picture

Excellent! Thank you. I had a similar problem, but with a view that required some css too (jcarousel). I added

$vars['styles'] = drupal_get_css();

and my problems were solved. Thanks for posting!!

-James

parasolx’s picture

seriously, comment #35 solved my problem also.

i think it should be nominate in documentation since there is no problem regarding the code. when comes to complex modification, it need to do some adjustment.

thank you.

redndahead’s picture

It is documented in our documentation section.

sammyframson’s picture

#35 worked perfectly for me as well after much time and frustration. I did have a few bonehead moments however... I neglected to change my specific view name...e.g. in my case from "page_image_rotator" to "rotating_banner" - a couple important areas to make the change.

In template.php have.
function mythemename_preprocess_page(&$vars, $hook) {
$vars['embedded_view'] = views_embed_view('page_image_rotator', 'block_1');
$vars['scripts'] = drupal_get_js();
}

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

print $embedded_view;

Thanks for the great module and the solution!

yngens’s picture

Another of doing this without adding additional code into template.php is to create a region and place views block in the region.

yan’s picture

#35 did the trick for me, thanks!