Hello,

I have a view composed of events with image, text, characteristics, ... The field ("field_event_access") to indicate the characteristics is a multiple choice list. I can determine if the event is free access or on booking, free or paid, ...

In View module, I can't display custom text if an event has the following features : "On booking" / "Paid" or "On booking" / "Free".

I tried this :

{% if field_event_access = 'On booking' and 'Paid' %}
{{ nothing_1 }}
{% else %}
{% endif %}
{% if field_event_access = 'On booking' and 'Free' %}
{{ nothing_2 }}
{% else %}
{% endif %}

But nothing...

Any idea ?

Thanks !

Comments

vedprakash’s picture

Try this:
{% if field_event_access == 'On booking' and field_event_access == 'Paid' %}
{{ nothing_1 }}
{% else %}
{% endif %}
{% if field_event_access == 'On booking' and field_event_access == 'Free' %}
{{ nothing_2 }}
{% else %}
{% endif %}

You can also rewrite the views results before rendering:

function module-name_views_pre_render(\Drupal\views\ViewExecutable $view)
{
if ($view->id() == 'views-machine-name' && $view->getDisplay()->display['id'] == 'block-or-page-id') {
$v->_entity->get('field_name')->value); // Get the field value
$v->_entity->set('field_name', 'your-custom-value'); // Alter existing field value
}
}

Hope this information helpfull for your queries.

Gilles G.’s picture

Sorry for my late response. It's ok with this ! Just "==" rather "=" !!! ;-)