You are here

form-options-attributes--select--options-attributes.html.twig in Form Options Attributes 8

{% apply spaceless %}
    <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"' }} {{ options_attributes[option.label][sub_option.value] }}>{{ sub_option.label }}</option>
                    {% endfor %}
                </optgroup>
            {% elseif option.type == 'option' %}
                <option value="{{ option.value }}"{{ option.selected ? ' selected="selected"' }} {{ options_attributes[option.value] }}>{{ option.label }}</option>
            {% endif %}
        {% endfor %}
    </select>
{% endapply %}

File

templates/form-options-attributes--select--options-attributes.html.twig
View source
  1. {% apply spaceless %}
  2. <select{{ attributes }}>
  3. {% for option in options %}
  4. {% if option.type == 'optgroup' %}
  5. <optgroup label="{{ option.label }}">
  6. {% for sub_option in option.options %}
  7. <option value="{{ sub_option.value }}"{{ sub_option.selected ? ' selected="selected"' }} {{ options_attributes[option.label][sub_option.value] }}>{{ sub_option.label }}</option>
  8. {% endfor %}
  9. </optgroup>
  10. {% elseif option.type == 'option' %}
  11. <option value="{{ option.value }}"{{ option.selected ? ' selected="selected"' }} {{ options_attributes[option.value] }}>{{ option.label }}</option>
  12. {% endif %}
  13. {% endfor %}
  14. </select>
  15. {% endapply %}