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?

3
  • Try this Views_field_view module Commented Feb 13, 2017 at 6:46
  • @logeshvaran before you comment I answer it with suggest use this module ;)
    – Yuseferi
    Commented Feb 13, 2017 at 6:47
  • @zhilevan okay fine Commented Feb 13, 2017 at 6:49

2 Answers 2

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();
3
  • 1
    Vote up, programmatically method is another method for achieve this,
    – Yuseferi
    Commented Feb 13, 2017 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 Commented Feb 14, 2017 at 4:36
  • @user3386779 pick one and write all the code there.
    – No Sssweat
    Commented Feb 14, 2017 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.

3
  • how to use this module.I have two tpl file Commented Feb 13, 2017 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
    – Yuseferi
    Commented Feb 13, 2017 at 6:57
  • @user3386779 did you try that?
    – Yuseferi
    Commented Feb 13, 2017 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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