1

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

new|New

old|Old

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">
                NEW
            </div>
        {% else %}
            <div class="icon medium">
                OLD
            </div>
        {% endif %}
        <h5 class="card-title">{{ fields.title.content }}</h5>
    </div>
</div>

Thanks for helping!

0

1 Answer 1

3

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)

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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