I have a entity A with an entity reference to entity B, and an image field. I created a view to display an entity A. I want to link the image field to the page displaying the referenced entities B.

Firstly, I've added the entity reference field in my view and checked "Exclude from display", in order to get in the image field the replacement token, but I could not get the link. I just get the the entity B title.

Afterwards, I added a relationship to entity B in my view. No more success.

Could you help me?

1 Answer 1


ER fields store only the ID of the referenced entity.

Pulling in other information about the referenced entity usually involves adding Relationships, but some details can also be shown through the Formatter Field setting.

Set Formatter to Entity ID and Rewrite

Without adding the Relationship edit the ER field, set the Formatter to Entity ID, then under Rewrite results turn on Override the output of this field with custom text and enter something like this into the Text field:

<a href="/node/{{ field_myreferencetoB__target_id }}">{{ field_myImagefield }}</a>

Check the correct tokens under Replacement patterns a bit lower under the Text field.

You can also achieve similar result with Output this field as a custom link which has more options for the link if you need them. In this case the Text field will only hold the image token and this option will contrast the anchor HTML.

This approach is helpful when you have a multivalue field it will be possible to show all values in the same row, while using a Relationships usually splits them into separate rows and it requires more steps to aggregate them.

Use the ER Relationship

If you add the ER Relation ship you will be able to add the Link to content field and make it use that Relationship to show the link to the Referenced entity instead of link to the original row entity.

You may want to use the Output the URL as text option to make the token output more predictable.

Now you have the referenced entity link in your Views you can use it to Rewrite other fields.

  • Many thanks for this reply! I will give it a try. Commented May 21, 2021 at 10:14

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.