Check for (non-)empty fields

Category
Drupal Version

Satisfies a comment on drupal.org:

Someday I would like to spend the time to make a list of the various field types and the best way to check whether they are empty so I can stop Googling this thread every few months.

Basic field

Expensive (render) check

{% if content.field|render is not empty %}
     {{ content.field }}
{% endif %}

Note that this can be an expensive (resource-wise) check to make.

Basic check

{% if node.field.value %}
  {{ content.field }}
{% endif %}

Entity Reference fields

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

Note

This should be compiled over on drupal.org in the near future, anyways.