Skip to content

Instantly share code, notes, and snippets.

@thejimbirch
Created August 18, 2016 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thejimbirch/1cd31ee3b39ea4316ac3ca801be44141 to your computer and use it in GitHub Desktop.
Save thejimbirch/1cd31ee3b39ea4316ac3ca801be44141 to your computer and use it in GitHub Desktop.
Styling Exposed View Forms in Drupal 8 - Twig Template
{#
/**
* @file
* Theme override for a select element.
*
* Available variables:
* - attributes: HTML attributes for the select tag.
* - options: The option element children.
*
* @see template_preprocess_select()
*/
#}
{% spaceless %}
<div class="select-style">
<select{{ attributes }}>
{% for option in options %}
{% if option.type == 'optgroup' %}
<optgroup label="{{ option.label }}">
{% for sub_option in option.options %}
<option value="{{ sub_option.value }}"{{ sub_option.selected ? ' selected="selected"' }}>{{ sub_option.label }}</option>
{% endfor %}
</optgroup>
{% elseif option.type == 'option' %}
<option value="{{ option.value }}"{{ option.selected ? ' selected="selected"' }}>{{ option.label }}</option>
{% endif %}
{% endfor %}
</select>
</div>
{% endspaceless %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment