Is there any programming method to hide or show each Field's Label of custom content type in twig template files, regardless of fields manage display
setting?
2 Answers
Heres a little twig filter module that does just that: https://www.drupal.org/project/twig_field_value. If you study the code you can see how the filter works and deduce how it works programatically.
Override the template for that specific field and don't print the label.
field--field-thing.html.twig
{% if multiple %}
<div{{ attributes }}>
{% for item in items %}
<div{{ item.attributes }}>{{ item.content }}</div>
{% endfor %}
</div>
{% else %}
{% for item in items %}
<div{{ attributes }}>{{ item.content }}</div>
{% endfor %}
{% endif %}
Alternatively, you can preprocess the field and remove the label/change the display, but personally I would do it in the templates so later on the label could easily be added back in.
-
I think it is best to give a code example...– user16289Aug 17, 2016 at 20:25
-