Hey there,
i have a view where i have overriden the 'default' display to have an alternative block display for the view.
in my code i want to programmatically get the view and display it. Inside my page callback function i have the following -

  $output = '';
  $view = views_get_view('viewname');
  $output .= $view->execute_display('block');
  
  return $output;

problem is, no matter what i put inside execute_display() it only ever renders the 'default' display. is there another way to do this or is this a bug with views?

Comments

dawehner’s picture

Title: $ivew->execute display only executes default display » $view->execute display only executes default display
Status: Active » Fixed

Thats easy :)

The display id has always an numeric parameter, so the first block display is 'block_1'.

Views uses execute_display on quite important places, it should work :)

tayzlor’s picture

Status: Fixed » Closed (fixed)

aaah, doh! brilliant thanks =) closing this.

geshan’s picture

executing a block display returns an array so print or return $output['content'];

sagannotcarl’s picture

Version: 6.x-2.6 » 6.x-2.11
Status: Closed (fixed) » Active

Does anyone have an example of this for panel panes?

I'm calling the following and it still returns the default display.

  $view = views_get_view('events');
  $view->init_display('pane_3');

  $events = $view->execute_display('pane_3', array('3166'));
  
  $output = $events;

replacing pane_3 with panel_pane_3 isn't working either.

I am using this somewhere else calling a views context pane and using init_display('ctools_context_1') and execute_display('ctools_context_1') worked great. I just can't figure out how to call a panel pane in this way.

merlinofchaos’s picture

You should do a dsm on array_keys($view->display) to make sure you're using the right ID. THat is the most likely problem. 'pane_3' is definitely not right.

sagannotcarl’s picture

StatusFileSize
new25.03 KB

Thanks for the tip.

dsm(array_keys($view->display)) returns panel_pane_3 (along with the other displays - see screenshot). But putting that into the execute_display still doesn't work.

Here is some more info:
* Using $view->execute_display('pane_3') returns the default display
* Using $view->execute_display('panel_pane_3') returns nothing

Any other suggestions for troubleshooting?

merlinofchaos’s picture

You probably want $view->preview() not $view->execute_display() now that I think on it. I forget what execute_display() will get you on a panel pane, but preview() is guaranteed to always get you rendered output. execute_display() gets you whtaever the display thinks is appropriate (i.e, an array for a block, etc).

  $view = views_get_view('viewname');
  $view->set_display('panel_pane_3');
  $view->set_arguments(array('123'));
  $output = $view->preview();
sagannotcarl’s picture

Status: Active » Fixed

Perfect! Thanks so much!

Status: Fixed » Closed (fixed)

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