0

In Drupal8, I have created a view of content and add a relationship of the user account field which is referenced entity of the content. So, Basically I have one content type and in the account fields I have added one content referenced field, there user can select multiple values.

Now in the view I am showing the content and using the Global custom field I am overriding the output of the view.

In the field of referenced entity under view I am getting multiple values like 1,2,3,4,5 and I want something like if node id is present inside this multiple values then I want to display some text.

Can anybody let me know how can I achieve this?

I have tried something like below under Global: custom text field but it did not worked.

{% if nid in field_ref_content %}
  <p>Lorem Ipsum</p>
{% endif %}

I have tried to override the twig as well for that field and able to achieve the things what I want to show like some custom text, but that only rendered when we are using that field in view.

when I used that field's replacement pattern inside that Global: custom text, that is returning only the default value which is 1,2,3,4,5 not the one which I have override using the view field override hook

Hook_preprocess_views_view_field

Can someone please guide me, I spend so much time for this but no luck.

Thanks in advance.

1
  • IIUC Contextual Filter for the reference field might help. Select to provide a fixed value, enter your value, and then below validation section what to display if the argument matches. Arguments from Contextual filters also become available as token to be used in other areas of Views, maybe it's what you need for your Global text field. – prkos Apr 20 at 10:13

Your Answer

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

Browse other questions tagged or ask your own question.