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

31 May · by Tim Kamanin · 2 min read

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

Required for comment verification



Sergey Korzh

Views exposed form layout (https://www.drupal.org/project/vefl) helps with exposed form theming.

Reply · 2 years, 8 months ago
someguy

HOW DO YOU THEME THE WIDGETS IN THE EXPOSED FILTER

Reply · 6 years, 6 months ago
René

Thank you very much. A great time safer :)

Reply · 6 years, 6 months ago
alibama

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 :)

Reply · 6 years, 6 months ago
Albert

Thanks!

Reply · 6 years, 6 months ago
chill

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

Reply · 6 years, 6 months ago
PedroKTFC

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

Reply · 6 years, 6 months ago
Aaron

Thanks! You just saved me a little brain ache.

Reply · 6 years, 6 months ago