How To Display Views' Exposed Filter In A Block And Theme It

If you build a View with an exposed filter you may want to put this filter in a block. This is can be done to separate filter from view results and to display exposed filter in any part of your website.

To do this, go and edit your view.

  • 1. Under Basic settings you will see an option: Exposed form in block (UPD: in new Views interface the path looks like this: Advanced > Exposed Form) Select Yes and save your View.
  • 2. Now you can go to Blocks and see your View’s Exposed Filter appeared in the block’s list. Nice!

But what if you want to theme this block and change the way exposed filter behaves, what do you do?

Since there is no any mention of “exposed filter in a block template file” in Views Theming information list, it is a bit tricky to guess which file to edit and how to name it. Here is what you should do:

  1. Go to Views installation folder (sites/all/modules/views) and look in ‘theme’ folder. There you will find ‘views-exposed-form.tpl.php’ file.
  2. Copy this file to your current theme directory, in my case it is sites/all/themes/timonweb
  3. Now, check your views name, in my case, it is ‘user-comments’.
  4. Rename your newly copied file by following this formula: views-exposed-form--view-name.tpl.php (NOTE “--”). In my case file’s name is: views-exposed-form--user-comments.tpl.php
  5. Clear your theme cache by flushing it with admin_menu module, or by going to your View and clicking “Rescan Template Files” under Style settings -> Theme Information.

That’s it, now you can edit views-exposed-form--user-comments.tpl.php file and all changes will be shown in a block with your exposed filter.

Enjoy!

Comments

Submitted by Aaron on Tue, 06/07/2011 - 07:55

Thanks! You just saved me a little brain ache.

Submitted by Tim on Thu, 06/09/2011 - 17:19

You're welcome Aaron )

Submitted by chill on Sun, 12/11/2011 - 13:13

Yes, thats good. But any ideas, how to alter or change the Widgets theme (template)?

Thanks, --chill

Submitted by Albert on Sat, 02/18/2012 - 07:16

Thanks!

Submitted by alibama on Wed, 02/22/2012 - 16:46

the view i'm working from has several pages in it and I'm only trying to style the third page in the view, views-exposed-form--solr_funk-page_3.tpl.php doesn't work... after playing in firebug a minute found the answer (drupal 6 with views 3) the answer that worked for me is

block-views--exp-solr_funk-page_3.tpl.php

hope this helps, and thanks for pointing in the right direction :)

Submitted by PedroKTFC on Tue, 04/24/2012 - 13:25

This is great but I've also used Better Exposed Filters to get check boxes. I'd like to mix this with an accordion module, always in a separate block to the results. Any ideas how I might do this?

Thanks

Submitted by René on Wed, 05/08/2013 - 18:52

Thank you very much. A great time safer :)

Add new comment

You are here