I have created twig template to override SELECT element for SELECT-element in user exposed filters.

However I can't figure out how to make it only work within a specific view "testing" ?


You should implements hook_theme_suggestions_HOOK_alter() to add a suggestion for 'select' element. Then create a new twig template in THEME/templates folder with the name 'select--$view_id.html.twig'.

Example code:

function HOOK_theme_suggestions_select_alter(array &$suggestions, array $variables) {
  $routeObject = \Drupal::routeMatch()->getRouteObject();
  $view_id = $routeObject->getDefault('view_id');
  $display_id = $routeObject->getDefault('display_id');

  if (!empty($view_id)) {
    $suggestions[] = 'select__' . $view_id;

    if (!empty($display_id)) {
      $suggestions[] = 'select__' . $view_id . '_' . $display_id;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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