Boolean field inside node twig renders ok but does not work in if statement I have an node twig and I want to use field of that node inside if of that twig. I managed to get the boolean value via content.field_sample|raw. But it looks like it doesn't work in if statement. For give code:

Value: {{ content.field_sample|raw }}
{% if content.field_sample|raw == '1' %}
    OK
{% else %}
    Error
{% endif %}


I get output:

Value: 1
Error


Sames goes for {% if content.field_sample|raw == 1 %}. 

{% if content.field_sample|raw == true %} always returns true, regardless the boolean is on or off (it returns true for both Value: 0 and Value: 1). I guess it's  because it just checks if fields exists.
In content is the render array of the field output. A boolean is probably a text in #markup. What text this is for 0/1 can be configured in the display mode. But don't try to find it there, better use for coding the node. There you get the values directly from the database.

{% if node.field_sample.value %}