{% if config.DEBUG %}<span class="debug-hint" title="{{ self._TemplateReference__context.name }}">?</span>{% endif %}

<div class="field {{ content.__class__.__name__.lower() }}">

    <label for="{{ content.ref_id }}">{% if content.label %}{{ content.label }}{% endif %}
        <select
            id="{{ content.ref_id }}"
            name="{{ content.prefix }}.{{ content.name }}"
            class="{% if content.errors %}invalid{% endif %}"
            {% if content.readonly %}disabled{% endif %}
            {% if content.required %}required{% endif %}
            {% if content.multi %}multiple{% endif %}
        >

        {% if not content.multi and content.empty_label %}
        <option value=''>{{ content.empty_label }}</option>
        {% endif %}
        {% for value, label in content.choices %}
            {% if not value is string and value is iterable  %}
                <optgroup label="{{ label }}">
                    {% for subvalue, sublabel in value %}
                        <option value="{{ content.value_string(subvalue) }}" {% if content.checked(subvalue) %}selected{% endif %}>{{ sublabel }}</option>
                    {% endfor %}
                </optgroup>
            {% else %}
            
                <option value="{% if not value is none %}{{ content.value_string(value) }}{% endif %}" {% if content.checked(value) %}selected{% endif %}>{{ label }}</option>
            {% endif %}
        {% endfor %}

        </select>
    </label>

    {% if self.help()|trim %}
    {% block help %}
        {% if content.help_text %}
           <span class="help">{{ content.help_text }}</span> 
        {% endif %}
    {% endblock %}
    {% endif %}

</div>
