Same filename in this branch
  1. 10 core/modules/system/templates/select.html.twig
  2. 10 core/themes/stable9/templates/form/select.html.twig
  3. 10 core/themes/starterkit_theme/templates/form/select.html.twig
Same filename and directory in other branches
  1. 8.9.x core/modules/system/templates/select.html.twig
  2. 9 core/modules/system/templates/select.html.twig

Default theme implementation 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
Returns the element properties for this element.

File

core/modules/system/templates/select.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation 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. * @ingroup themeable
  13. */
  14. #}
  15. {% apply spaceless %}
  16. <select{{ attributes }}>
  17. {% for option in options %}
  18. {% if option.type == 'optgroup' %}
  19. <optgroup label="{{ option.label }}">
  20. {% for sub_option in option.options %}
  21. <option value="{{ sub_option.value }}"{{ sub_option.selected ? ' selected="selected"' }}>{{ sub_option.label }}</option>
  22. {% endfor %}
  23. </optgroup>
  24. {% elseif option.type == 'option' %}
  25. <option value="{{ option.value }}"{{ option.selected ? ' selected="selected"' }}>{{ option.label }}</option>
  26. {% endif %}
  27. {% endfor %}
  28. </select>
  29. {% endapply %}

Related topics