Score:1

How to wrap select list in custom html?

zw flag

I have a select list created by views exposed filters.

When I debug the templates used. I have the exposed filter template, then the select list is in a seperate template.

I tried just putting my html in the exposed filter around {{form}}. This put the html around the whole form, including labels, other containers etc, which didn't work for my situation.

So I am trying to target the select list directly using this answer here

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[] = 'selectlist__' . $view_id;

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

On first load of view it works. When I update the view using ajax the twig template is no longer loaded.

I check the template suggestions and it suggests the same twig template for before using ajax and after. I am at a loss on how I can edit the select list for a specific view whilst maintaining ajax use.

cn flag
It's because of the route check - an AJAX call doesn't happen in the same route as the page it's called from (it'll be /system/ajax or something else)
Jaypan avatar
de flag
What are you actually trying to output?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.