You are here

select.html.twig in Open Social 8.7

Theme override for a select element.

Available variables:

  • attributes: HTML attributes for the select tag.
  • input_group: Flag to display as an input group.
  • options: The option element children.
  • prefix: Markup to display before the input element.
  • suffix: Markup to display after the input element.

File

themes/socialbase/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. * - input_group: Flag to display as an input group.
  9. * - options: The option element children.
  10. * - prefix: Markup to display before the input element.
  11. * - suffix: Markup to display after the input element.
  12. *
  13. * @see template_preprocess_select()
  14. */
  15. #}
  16. {% spaceless %}
  17. {% if input_group %}
  18. {{ attach_library('socialbase/form--input-groups') }}
  19. <div class="input-group">
  20. {% endif %}
  21. {% if prefix %}
  22. {{ prefix }}
  23. {% endif %}
  24. {% if multiselect %}
  25. {{ attach_library('socialbase/select2') }}
  26. {% else %}
  27. {# Browsers do not recognize pseudo :after selectors, we must create a wrapper
  28. # around the select element to style it properly.
  29. # @see http://stackoverflow.com/q/21103542
  30. #}
  31. <div class="select-wrapper">
  32. {% endif %}
  33. {% set classes = ['form-control'] %}
  34. <select{{ attributes.addClass(classes) }}>
  35. {% for option in options %}
  36. {% if option.type == 'optgroup' %}
  37. <optgroup label="{{ option.label }}">
  38. {% for sub_option in option.options %}
  39. <option
  40. value="{{ sub_option.value }}"{{ sub_option.selected ? ' selected="selected"' }}>{{ sub_option.label }}</option>
  41. {% endfor %}
  42. </optgroup>
  43. {% elseif option.type == 'option' %}
  44. <option
  45. value="{{ option.value }}"{{ option.selected ? ' selected="selected"' }}>{{ option.label }}</option>
  46. {% endif %}
  47. {% endfor %}
  48. </select>
  49. {% if not multiselect %}
  50. </div>
  51. {% endif %}
  52. {% if suffix %}
  53. {{ suffix }}
  54. {% endif %}
  55. {% if input_group %}
  56. </div>
  57. {% endif %}
  58. {% endspaceless %}