B
B
Bogdan Zhuvak2020-06-23 12:09:16
Drupal
Bogdan Zhuvak, 2020-06-23 12:09:16

Why is drupal 8 comparison operator not working?

Wrote this code

{% if content.field_size_amount == 2 %}
      <p>True</p>
{% endif %}

It doesn't output anything. In the admin panel, the field is a list of integers.
If you {{ content.field_size_amount }}output two.
And how to understand it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
andead, 2020-06-23
@SoraxBZ

The content.field_size_amount is an array, not a number. Comparing an array to a number is useless. If you need to get the field value, then you need to take data from the entity:
node.field_size_amount.value

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question