When we use checkbox or radio element, we often use in the label.

Term of service, for example.

term of service

But label in [template/form/form-element.html.twig] can't render html tag like .

current code

{% if label_display == 'before' %}
      <label {{ attributes.addClass(labelclass).setAttribute('for', input_attributes.id) }}>
        {{ input_title }}
      </label>
    {% endif %}
    <input{{ input_attributes.addClass(inputclass) }}>
    {% if label_display == 'after' %}
      <label {{ attributes.addClass(labelclass).setAttribute('for', input_attributes.id) }}>
        {{ input_title }}
      </label>
    {% endif %}

Change the code to

{% if label_display == 'before' %}
      <label {{ attributes.addClass(labelclass).setAttribute('for', input_attributes.id) }}>
        {{ input_title | raw }}
      </label>
    {% endif %}
    <input{{ input_attributes.addClass(inputclass) }}>
    {% if label_display == 'after' %}
      <label {{ attributes.addClass(labelclass).setAttribute('for', input_attributes.id) }}>
        {{ input_title | raw }}
      </label>
    {% endif %}

Comments

cobenash created an issue. See original summary.

cobenash’s picture

StatusFileSize
new791 bytes
cobenash’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 2: twig-add-raw-filter-to-label-3034621-1.patch, failed testing. View results

cobenash’s picture

Status: Needs work » Needs review
ldavidsp’s picture

StatusFileSize
new799 bytes

Status: Needs review » Needs work

The last submitted patch, 6: twig-add-raw-filter-to-label-3034621-6.patch, failed testing. View results

cobenash’s picture

#6 doesn't work.

striptags will ignore html <a> tag.

The question is {{ input_title }} will display text in plain text without any html tag.

#2 can fix the issue and print with html tag.

cobenash’s picture

Status: Needs work » Needs review
npralhad’s picture

#2 works perfectly for me.

hatuhay’s picture

Status: Needs review » Fixed

  • hatuhay committed 0a6dfa0 on 8.x-4.x authored by davidsp25
    Issue #3034621 by cobenash, davidsp25: Label in template/form/form-...

  • hatuhay committed 359ca7c on 8.x-4.x authored by cobenash
    Issue #3034621 by cobenash, davidsp25, hatuhay: Label in template/form/...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.