5

I have filter in separate view and want to pass the value to another view and get the filter result in Drupal.

Scenario: I have two views, one for filter and another for filter result.

I want to filter based the content: title. In another view I have to fetch the result and display based on title filter.

My question: How can I argument from one view to another view?

  • Try this Views_field_view module – logeshvaran Feb 13 '17 at 6:46
  • @logeshvaran before you comment I answer it with suggest use this module ;) – Yusef Mohamadi Feb 13 '17 at 6:47
  • @zhilevan okay fine – logeshvaran Feb 13 '17 at 6:49
3

Here is how you can do it programmatically:

// load and display view A
$view_A = views_get_view('view_A_name');
// execute view
$view_A->execute();
// get all nids from the result 
foreach ($view_A->result as $result) {
   // capture the result of your field in an array. 
   $values[] = $result->field_machine_name; 
}
// render view
print $view_A->render();

// now load view B
$view_B = views_get_view('view_B_name');
// set arguments for view
$view_B->set_arguments(array(implode(",", $values)));
// execute view
$view_B->execute();
// render view
print $view_B->render();
  • 1
    Vote up, programmatically method is another method for achieve this, – Yusef Mohamadi Feb 13 '17 at 8:46
  • where to write the code I have two view tpl parent(perspective.tpl) and child (submenu.tpl) In which file I have to write this code – user3386779 Feb 14 '17 at 4:36
  • @user3386779 pick one and write all the code there. – No Sssweat Feb 14 '17 at 5:35
2

Use Views Field View module

There are a lot of cases in views where you want to embed a list inside each row. One example could be, you have a list of groups, and for each groups you want to list the first and last name of all of their members.

This can be achieved with this module, as views_field_view allows you to embed one view into another view and pass arguments along.

And Also if You are developer and you want to achieve it programmatically you can use views_get_view function.

  • how to use this module.I have two tpl file – user3386779 Feb 13 '17 at 6:48
  • install that module, the in your primary views, in golobal section add View field and pass title to secondary views, see some tutorial about how use this module ( it's very simple ) as example webomelette.com/view-within-view-fields-module – Yusef Mohamadi Feb 13 '17 at 6:57
  • @user3386779 did you try that? – Yusef Mohamadi Feb 13 '17 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.