Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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
Comment #1
anthonylindsay CreditAttribution: anthonylindsay commentedI could not reproduce this. I've got a page build function like this, as a callback from hook_menu()
and it is returning results as expected. I'm calling both displays from one view and one display from another view.
Comment #2
Strutsagget CreditAttribution: Strutsagget commentedI 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.
Comment #3
Strutsagget CreditAttribution: Strutsagget commentedComment #4
Strutsagget CreditAttribution: Strutsagget commentedComment #5
anthonylindsay CreditAttribution: anthonylindsay commentedAha, 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.
Comment #6
phponwebsites CreditAttribution: phponwebsites commentedI'm also getting same issue. IS any other solution to view all views in a page using views_embed_view for JSON views?