In a custom views-view-fields.html.twig I do print a list field (field_status) without issues. The values are:



But if i want to do an if/else statement for printing different div containers i do get always printed the div container from else. Does anybody have an idea what i am doing wrong? I tried it too with module Twig Field Value, but i do have the same issues.

<div class="card h-100">
    <div class="card-body">
        {% if fields.field_status.content == 'new' %} // |striptags , |raw or a capital value e.g. New do not work , Twig Field Value also do not work: content.field_status|field_value
            <div class="icon medium">
        {% else %}
            <div class="icon medium">
        {% endif %}
        <h5 class="card-title">{{ fields.title.content }}</h5>

Thanks for helping!


1 Answer 1


If you want to compare the left part of the field list you need the raw database value from the entity.

You find the entity in the row variable of views-view-fields.html.twig :

{% if row._entity.field_status.value == 'new' %}

See Access row value in template_preprocess_views_view_fields(&$variables)

  • You´re great, thanks a lot! Now it works without issues. I´ve spend hours and hours to find a solution.
    – druplash
    Jan 19, 2022 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.