Drupal - How to name views-exposed-form.tpl.php per views display

For Drupal 7, you can use views-exposed-form--view_name--display_name.tpl.php (Replace underscores with dashes in view name and display name.)

It worked for me that way.


in drupal8

/admin/structure/views/view/event_related

would be

views-exposed-form--event_related.html.twig


Everything is possible in Drupal ;)

Probably Views does not automagically provide template suggestions for the exposed filter, like it does for the fields themselves. So you will need to do a little bit more work for this one:

  1. Use the the devel_themer module to find out what function/template is theming that exposed filter.
  2. Create a preprocessor for that theme function/template. In your preprocessor you can then insert dynamic template suggestions that will fire off based on any condition you want. You can create this preprocessor either in your custom theme's template.php file or in one of your custom modules. This D.O. article will guide you with creating the dynamic template suggestion.

I will assume that you will be displaying different Views displays based on a URL path. If this were the case, then you can use Drupal's arg() function in your preprocessor to figure out what is the View display that you are currently displaying, and construct your template suggestion using that information.

Once you've setup your suggestions properly, then Drupal would automatically call the appropriate template and voilá, you have different filter templates based on the path (or any other condition that you specify in your preprocessor).

Tags:

Views

Theming