Verify a field is not empty What is the best method to check if a field is empty in a node template.

In node--example.html.twig we can use "content" variable.

I can't use check like checking a block

{% if content.field_example  %}


I can use something like this:

{% if content.field_example['#object'] is defined  %}


But what is the best method?
Like I also wrote in How can you render fields from an entity reference in node templates? [Drupal 8], content is a render array that contains data prepared for displaying.

If you want to check or compare something, use the values instead, which are available on the node object.

{% if node.field_example.value %}.

Note that the property depends on the field type. If it's a reference field, you need to use target_id instead. The referenced question links to a entity field API cheat sheet that lists common field types and their properties.