Dhofca
Dhofca

Reputation: 385

Remove colon from form labels

I'm using

{{ form_label(form.fieldName) }}

and it's generating label with colon (:) in the end. How to remove auto-adding it to labels?

Upvotes: 1

Views: 1113

Answers (3)

sglessard
sglessard

Reputation: 3156

Simply, you can use vars.label on the field :

<label for="{{ form.fieldName.vars.id }}">{{ form.fieldName.vars.label }}</label>

Upvotes: 0

Dhofca
Dhofca

Reputation: 385

Thanks Patt, the solution is:

{% form_theme form _self %}

{% block field_label %}
{% spaceless %}
    {% 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 %}
        {% set label = name|humanize %}
    {% endif %}
    <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ label|trans({}, translation_domain) }}</label>
{% endspaceless %}
{% endblock field_label %}

Upvotes: 0

Mick
Mick

Reputation: 31919

You can customize the form rendering using Form Theming. What you will have to customize is the form_label block.

Upvotes: 1

Related Questions