How To Display Views' Exposed Filter In A Block And Theme It31 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.
- 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.
- 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:
- Go to Views installation folder (sites/all/modules/views) and look in 'theme' folder. There you will find ' views-exposed-form.tpl.php' file.
- Copy this file to your current theme directory, in my case it is sites/all/themes/timonweb
- Now, check your views name, in my case, it is 'user-comments'.
- 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
- 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!