Skip to main content
Check the field value in Twig Drupal 9
{% if 'some field value' in entity.field_name[0] %} //Output the result that we need
 {% else %}
//Output the result if the validation of the value is not successful
 {% endif %}


  • entity - entity type
  • field_name - machine name of the field we need


{% if 'In stock' in product.field_stock[0] %}
{{ product.field_stock }}
{% else %} { product.field_stock }} 
{% endif %} 


About The Author

Author of this blog. In SEO for over 10 years. In addition to SEO, I am interested in everything related to technology and earnings on the Internet, which I try to share with readers.