8

I tried views-exposed-form--"view_name"--"display_name".tpl.php but it doesn't work. Is it possible to make a template file which applies only to the exposed filter of a views display?

I have two exposed filters from two different displays within a same view, and I would like to theme the two exposed filters differently by two template files.

3

4 Answers 4

2

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

25

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.

3
  • This worked form me. Here is an example of my exposed form template name: views-exposed-form--trunk_shows--panel-pane-1.tpl.php
    – albertski
    Commented Jan 27, 2016 at 17:00
  • Even though your views-exposed-form--view_name--display_name.tpl.php may not be listed when you do this, on adding your new template file you should also edit the view, click on the Advanced->Other->Theme->Information, and then click the Rescan Template Files button.
    – kbrinner
    Commented Apr 19, 2016 at 21:40
  • You don't need the display name, if you don't need to be that specific. For my block view, "Events View", naming my template file "views-exposed-form--events-view.tpl.php" worked for me. Thanks, @kaimlaluno. This should probably be the accepted answer.
    – ProGrammar
    Commented Mar 15, 2017 at 18:35
3

in drupal8

/admin/structure/views/view/event_related

would be

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

1

For drupal 8, theme debug mode does not display the available template suggestions. You can find out which ones are avaliable using kint() or create new ones in this hook:

/**
 * Implements template_theme_suggestions_node_HOOK_alter().
 * Add theme suggestions to the view exposed forms.
 */
function YOUR_THEME_theme_suggestions_views_exposed_form_alter(&$suggestions, $vars, $hook) {
  kint($vars['form']['#theme']);
  //$suggestions[] = 'views__exposed__form__' . $anything; 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.