Split a Views Exposed Form into Multiple Blocks

While working on a project for a customer we had the requirement to display different parts of an exposed form of a view in different regions of the page. Additionally not all parts of the form should be visible on all pages of the site (i.e. the search box should be visible on all pages whereas other exposed filters or sort options should be visible on the result pate only).
Normally we would manage this by using some hook_form_alter()-magic and/or create a custom block with a coded form in it. But a hint of Daniel Wehner (dawehner) pointed me to a different solution:

Multiple Views Displays

In Views you are able to clone an existing display, which means nothing else but creating a plain copy of it. In our case I cloned the page display containing the exposed form to split and modified some filter settings only. 

Other options (especially the page path) were not changed.

If you now look into the list of blocks, there is one block for both Views displays containing the corresponding exposed form. These blocks may be displayed on different pages and in different regions.

Stefan Borchert
  • CEO

Stefan maintains several Drupal contributed modules, has been working on Drupal core since the early days, and is author of Drupal 8 Configuration Management (Packt Publishing).