select.html.twig

Theme override for a select element.

Available variables:

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

@see\Drupal\Core\Form\FormPreprocess::preprocessSelect()

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/themes/stable9/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\Drupal\Core\Form\FormPreprocess::preprocessSelect()
  11. */
  12. #}
  13. <select{{ attributes }}>
  14. {% for option in options %}
  15. {% if option.type == 'optgroup' %}
  16. <optgroup label="{{ option.label }}">
  17. {% for sub_option in option.options %}
  18. <option value="{{ sub_option.value }}" {{ sub_option.selected ? ' selected="selected"' }}>{{ sub_option.label }}</option>
  19. {% endfor %}
  20. </optgroup>
  21. {% elseif option.type == 'option' %}
  22. <option value="{{ option.value }}" {{ option.selected ? ' selected="selected"' }}>{{ option.label }}</option>
  23. {% endif %}
  24. {% endfor %}
  25. </select>

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