I have used this below code to check if the field has a value

{% if content.field_title is not empty %}
    <p>{{ content.field_title }}</p>
{% endif %}

But p tag is rendering even though the field doesn't have a value. Same happening for {% if content.field_title is not null %} as well and {{ dump(content.field_title) }} is not an empty array if the field has no value. So how to check empty condition in twig for a field.

Edited: Trying to use the content object instead node/paragraph/term object. Here Verify a field is not empty used node object.

Thanks in advance!


1 Answer 1


Quite a few ways to check. For content fields in Twig I generally prefer:

{% if content.field_title['#items'].getValue() %}

Not the answer you're looking for? Browse other questions tagged or ask your own question.