How do I check if an image field is empty in a template file? I am trying to check if the user_picture field is empty using the twig template, but I am not able to do this.

I tried lots of ways:-

{% if node.user_picture.value %}
{% if node.user_picture.entity %}
{% if content.user_picture.value %}
{% if content.user_picture|render.entity %}
{% if content.user_picture|render %}




Sample of code:

  {% if node.user_picture.value %}
    &lt;p&gt;User-picture 02&lt;/p&gt;
    {{ user_picture }}
  {% else %}
    &lt;p&gt;Anymonus-picture 02&lt;/p&gt;
    &lt;div&gt;
      &lt;a href="#"&gt;&lt;img src="{{base_path}}/WEBSITE/themes/THEME/images/anonymous.jpg" alt=""&gt;&lt;/a&gt;
    &lt;/div&gt;
  {% endif %}
Use the method isEmpty() on the image field:

  {% if node.field_image.isempty %}
    &lt;p&gt;Field "field_image" is empty.&lt;/p&gt;
  {% endif %}


Although in this case you might need to check the user entity of the node author:

  {% if node.uid.entity.user_picture.isempty %}
    &lt;p&gt;Picture of the node author is empty.&lt;/p&gt;
  {% endif %}