Combine two view using module

i make a two view view-A and View-B. Now i want to combine them through a custom module.

please suggest me how can achieve this problem.

Comments

rhuffstedtler’s picture

I just had a need to do this same thing (there was probably a better way to solve my specific problem, but wrapping two views with a block was the fast way).

Things to do:

  1. Define your views (obviously). For reference purposes, I'm assuming that they are called view1 and view2 and that you have corresponding display names called display1 and display2.
  2. Create your module. For reference purposes, I'll assume you are calling it mymodule.
  3. Implement mymodule_block_info() to declare the block.
  4. Define your block in mymodule_block_view(), something like this
    function mymodule_block_view($delta = '') {

      $block = array();

      switch ($delta) {

        case 'myblock':

          $content = array(

            'first_view_content' => array(

              '#prefix' => '',

              '#suffix' => '',

              '#markup' => views_embed_view('view1', 'display1'),

            ),

            'second_view_content' => array(

              '#markup' => views_embed_view('view2', 'display2'),

            ),

          );

          $block['subject'] = 'Block subject goes here';

          $block['content'] = $content;

          break;

      }

      return $block;

    }
  5. Theme it as appropriate. In my case, I did a template for the block for all of the surrounding markup. My views were returning unformatted lists of nodes, so I themed a specific display mode for the kinds of nodes I was expecting in my return.

Hope that helps you get going in the right direction!

Read more: https://www.drupal.org/node/2418489