How to get value from {{ item.content }} I have a node named "reviews" and a custom field named "field_rating".
I created a field template named field--node--field_rating--reviews.html.twig.

I want inside the node to change the color with an if statement.

I try to do something like that:

{% for item in items %}
  {% if item.content &gt; 5 %}
    &lt;div style="background-color:green"&gt;{{ item.content }}&lt;/div&gt;
  {% endif %}
{% endfor %}


but it doesn't work.

Any suggestions?

Drupal Version 8.6.1
You are comparing an array with a number:

item.content &gt; 5


Try the field value instead:

element['#items'][key].value &gt; 5


Full code example:

{% for key, item in items %}
  {% if element['#items'][key].value  &gt; 5 %}
    &lt;div style="background-color:green"&gt;{{ item.content }}&lt;/div&gt;
  {% endif %}
{% endfor %}