Escaping html in select

I’m trying to build a select with countries and their corresponding flags.

Tried it both ways via ->control and ->select

<!--                --><?php //= $this->Form->control('country_id', ['label' => __('Country'), 'type' => 'select','escape'=>false, 'options' => $countries, 'empty' => true]); ?>

For the entity, i made a virtual field that returns me the country with flag:

    protected function _getNameWithFlag() {

        return '<span class="fi fi-'.strtolower($this->code).'"></span> '.$this->name;

The actual escaped string is shown to me in the select box, when “escape”=>true, but as soon as I turn on escape=>false, it just gives me the country name without the flag.

The icons should work, as I have it already displayed on the /index site in the Table representing the data.

I’m using country flags from

Any help on getting this work would be appreciated.

Check the resulting page html. It looks like the <span> node is being stripped from the <option>.

Double check that this is an allowed html node nesting. My IDE give a warning for this use.

If it is allowed, you may need to write your own element template to output these select item <option> tags.

You’re right, seems like its not possible to include tags in the option. Gonna switch to select2 or something similar.