Add a conditional CSS class to the label of the view exposed form I try to add a CSS class sr-only to the label of my Views exposed form.

In form-element-label.html.twig I added:

{% if title is not empty or required -%}
  &lt;label{{ attributes.addClass(classes) }}&gt;{{ title }}&lt;/label&gt;
  {% elseif title['#markup'] == "Search" %}
    &lt;label{{ attributes.addClass('sr-only') }}&gt;{{ title }}&lt;/label&gt;
{%- endif %}


When I debug {{ kint(title) }} I get:



What I'm doing wrong?
I don't think you need to check for "required" here, just check if the field is not empty, right?

You are first checking if a field is not empty so in the elseif the title will always be empty. You should have two ifs I for your logic to work I believe.

If not empty, do this: if it has this particular value do this otherwise do that.