Hi and thx for a great module!

Im trying to merge/print multiple json views in a custom module and it dosnt seam to work with views datasource (probebly works as intended).

Just wonder if there is any way around it?

function print_multiple_views_to_minimize_requests(){

   $display .=  views_embed_view('teams', 'page');
   $display .=  views_embed_view('players', 'page');

  print $display;
}

views_embed_view only seem to print one datasource view but i can print multiple ordinary views pages.

Comments

anthonylindsay’s picture

Status: Active » Closed (cannot reproduce)

I could not reproduce this. I've got a page build function like this, as a callback from hook_menu()

function json_build() {
  $output = '';
  $output .= '<h2>view 1</h2>';
  $output .= views_embed_view('jsontest', 'page_1');
  $output .= '<h2>view 2</h2>';
  $output .= views_embed_view('jsontest', 'page');
  $output .= '<h2>view 3</h2>';
  $output .= views_embed_view('anotherjsontest', 'page');
  return $output;
}

and it is returning results as expected. I'm calling both displays from one view and one display from another view.

Strutsagget’s picture

I have tried your code and still doesn't work.

Forgot to mention i have to unclick Views API mode in the format settings of the view.

Strutsagget’s picture

Issue summary: View changes
Strutsagget’s picture

Status: Closed (cannot reproduce) » Active
anthonylindsay’s picture

Status: Active » Closed (works as designed)

Aha, yes, sorry, you are right of course! Unclicking Views API mode will result in Views Datasource calling drupal_json_output, which I believe stops normal page processing.

So then the options are: use views_get_view_result to fetch the data and build your json up by hand.

Alternatively, you could try this:
Call one view and then, using something like hook_views_post_execute() hook into the processing of the view. Fetch the data with views_get_view_result() for all the other views, and then try merging in the three sets of rows. Then, in theory, rendering has not happened, but if you can manage to get the extra data in there I dare say it would turn out the JSON as you want it. Now I haven't tried it, but that's probably the approach I would try next.

In the mean time, I'll mark this as works as designed.

phponwebsites’s picture

I'm also getting same issue. IS any other solution to view all views in a page using views_embed_view for JSON views?