October CMS- Language Picker Component Twig

- 1 answer

I am trying to add flag icons for languages to my options in for loop. So far, I got this:

{{ form_open() }}
    <select name="locale" data-request="onSwitchLocale" class="form-control languageSwitcher">
        {% for code, name in locales %}
            <option value="{{ code }}" {{ code == activeLocale ? 'selected' }}>{{ name }}</option> 

        {% endfor %}

{{ form_close() }}

How can I do that?



You can't - well at least not by using the option html. An option html element can not have non text child elements or be styled.

See the following question

You can write your own custom html select/drop down/combo box and there are also many available 3rd party components that allow customisation. However out of the box the basic option element in the select html only allows a text node as a child element.