Drupal show exposed filter both in block and page

5.2k Views Asked by At

Need help again guys, Is there any way to display the exposed filters in a block and in a page without delete the filters of the page? I am using Exposed Form Filter at YES, the block with the filters is created but when i go to the page of the view, i cannot see the exposed filter.

i have for example page.tpl with the exposed block on it. But in templates/custom-page.tpl (where are the original exposed filters) cannot see them after enable Exposed Form Filter. What i want is that the exposed filters show up in both page and block.

I googled it but i couldn't find the solution yet. I would be gratefull if you can help me. Thanks!!! I am using Drupal 7.

3

There are 3 best solutions below

2
2pha On

You could set the exposed form not to be in a block (so it appears on the page). Then you could make your own block which has the exposed form in it (using the views functions to get the exposed form).
To get the exposed form check these links.
Drupal 7 Views 3: How to programmatically embed a Views exposed filter

OR.

You could expose the filters in a block, put this block on the views page and then use multiblock to make another copy of the exposed filter block to put somewhere else. This is probably easier.

1
Nux On

It's actually your idea, but I'll add it for others:

  1. Edit your view.
  2. Clone the "Page" in view.
  3. Rename the page something like "SearchBlock" (also change machine name to "search_block").
  4. Enable "Exposed form in block".
  5. Open blocks configuration (#overlay=admin/structure/block).
  6. Your new block will be somewhere on the button named something like: "Exposed form: your_view-search_block".

Point 3 is of course not required, but it will make things more obvious. And you usually need things to be obvious 6 months after you did something ;-).

BTW. You can remove filters from the block after you've cloned the page. There are only two requirements:

  1. Filters on the page and in the block must have the same machine name and operator settings.
  2. Block and filter must point to the same URL.

This also means you can add more blocks with various sets of filters.

0
marcvangend On

In Drupal 8 and 9 this is still a relevant question. I found that you can "trick" the view's page display into believing that the exposed form is not published as block. This will stop it from hiding the exposed form on the page display.

/**
 * Implements hook_views_pre_build().
 */
function mymodule_views_pre_build(ViewExecutable $view) {
  // Force the 'my_view' page display to always render the exposed form.
  if ($view->id() === 'my_view' && $view->getDisplay()->getPluginId() === 'page') {
    $view->getDisplay()->setOption('exposed_block', FALSE);
  }
}