select.html.twig

Same filename in this branch
  1. 9 core/themes/stable9/templates/form/select.html.twig
  2. 9 core/themes/starterkit_theme/templates/form/select.html.twig
  3. 9 core/themes/classy/templates/form/select.html.twig
  4. 9 core/modules/system/templates/select.html.twig
Same filename in other branches
  1. 8.9.x core/themes/stable/templates/form/select.html.twig
  2. 8.9.x core/themes/classy/templates/form/select.html.twig
  3. 8.9.x core/modules/system/templates/select.html.twig
  4. 10 core/themes/stable9/templates/form/select.html.twig
  5. 10 core/themes/starterkit_theme/templates/form/select.html.twig
  6. 10 core/modules/system/templates/select.html.twig
  7. 11.x core/themes/stable9/templates/form/select.html.twig
  8. 11.x core/themes/starterkit_theme/templates/form/select.html.twig
  9. 11.x core/modules/system/templates/select.html.twig

Theme override for a select element.

Available variables:

  • attributes: HTML attributes for the <select> tag.
  • options: The <option> element children.

See also

template_preprocess_select()

1 theme call to select.html.twig
Select::getInfo in core/lib/Drupal/Core/Render/Element/Select.php

File

core/themes/stable/templates/form/select.html.twig

View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override for a select element.
  5. *
  6. * Available variables:
  7. * - attributes: HTML attributes for the <select> tag.
  8. * - options: The <option> element children.
  9. *
  10. * @see template_preprocess_select()
  11. */
  12. #}
  13. {% apply spaceless %}
  14. <select{{ attributes }}>
  15. {% for option in options %}
  16. {% if option.type == 'optgroup' %}
  17. <optgroup label="{{ option.label }}">
  18. {% for sub_option in option.options %}
  19. <option value="{{ sub_option.value }}"{{ sub_option.selected ? ' selected="selected"' }}>{{ sub_option.label }}</option>
  20. {% endfor %}
  21. </optgroup>
  22. {% elseif option.type == 'option' %}
  23. <option value="{{ option.value }}"{{ option.selected ? ' selected="selected"' }}>{{ option.label }}</option>
  24. {% endif %}
  25. {% endfor %}
  26. </select>
  27. {% endapply %}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.