You have to custom the choice_label form in a custom theme (ex : radioHTML.html.twig) => I just add |raw to the label text
{%- block form_label -%}
{% if label is not same as(false) -%}
{% if not compound -%}
{% set label_attr = label_attr|merge({'for': id}) %}
{%- endif -%}
{% if required -%}
{% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
{%- endif -%}
{% if label is empty -%}
{%- if label_format is not empty -%}
{% set label = label_format|replace({
'%name%': name,
'%id%': id,
}) %}
{%- else -%}
{% set label = name|humanize %}
{%- endif -%}
{%- endif -%}
<{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>
{%- if translation_domain is same as(false) -%}
{{- label|raw -}}
{%- else -%}
{{- label|trans({}, translation_domain)|raw -}}
{%- endif -%}
</{{ element|default('label') }}>
{%- endif -%}
{%- endblock form_label -%}
Your form type just return html string in the choice_label option :
$builder->add('fieldName', EntityType::class, array(
'required' => true,
'class' => 'AppBundle\EntityName',
'choice_label' => function (EntityName $entity) {
$html = '<div>';
$html .= $entity->getName();
$html .= '</div>';
return $html;
},
'data' => null,
'multiple' => false,
'expanded' => true)
And then use it for your specific field like that in your twig TPL :
{% form_theme from.fieldNalme 'form/radioHTML.html.twig' %}
return new \Twig_Markup("<b>".$pay->getName()."</b><br />", "UTF-8");
– Nicolnicola<option>
content is not support by browsers. Try with css styles. – Cinder<option>
I rendered choiceType as radio button, sochoice_label
is in<label>
– Strangle