Drupal Views 2 & 3 Programmatically Render View with Arguments


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //OVERALL SCORE CALCULATION
  2. $display_id = 'default';
  3. $foo = '';
  4. $view = views_get_view('foobar');
  5. $view->set_display($default_id);
  6. $view->set_arguments(array($foo));
  7.  
  8. //replace name_of_filter with your filter machine name
  9. $view->set_display($display_id);
  10. $filter = $view->get_item($display_id, 'filter', 'name_of_filter');
  11. $filter['value']['value'] = $filter_value;
  12. $view->set_item($display_id, 'filter', 'name_of_filter', $filter);
  13.  
  14. //use this to count the results of your view
  15. $results_count = count($view->result);
  16. //print the rendered version of your view
  17. print $view->render();

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.