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

May 31, 2011 · by Tim Kamanin

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!

Want to get more 🔥 tips like this one?

Subscribe to get notified about new dev tutorials