0

I have a content type with a Related pages field, which an entity reference field for nodes.

How can view those nodes while still on the current node?

I tried to achieve this by creating a block view, but this shows all the nodes, whereas I want only the nodes referenced by the Related pages field.

screenshot

2
  • 1
    You need a contextual filter of the current node.
    – Kevin
    Commented Jun 11, 2021 at 18:11
  • I tried adding a contextual filter for field_related_documents but then nothing shows up, I'm not really sure how to use the contextual filter.
    – J.g
    Commented Jun 11, 2021 at 18:20

1 Answer 1

2

You don't need Views to do this, although it is possible to make it work with the correct configuration.

The easiest way is to configure what your Entity Reference field should display.

Configure "Manage display" for the ER field

Go to the Manage display page of your Content Type (admin/structure/types/manage/[myCT]/display/) and change your "Related pages" field to Rendered entity instead of Label.


Use Display modes

If you want to limit which fields of the referenced pages are shown on the page that references them, you can create a new Display mode (under Structure menu) where only the fields you want are enabled. Then use that mode on the ER field settings instead of the "Rendered entity".


Use Views Block with ER Relationship and Contextual filter

If you want to do it through Views to show the Parent fields on the Child node you need to add the Relationship for the ER field, then add the Contextual filter for the ID and Provide default value Content ID from URL, and when using fields make sure they use the Relationship to show the data from the referenced pages and not the (child) page you're currently viewing.

3
  • Furthermore, an entity reference field can use a view to show the list of referenced entities.
    – avpaderno
    Commented Jun 11, 2021 at 18:41
  • I am aware that this can be accomplished in other ways, but for other reasons, I believe I need to through views. I followed your steps, but now when I try to add a related document, I'm getting an error: "This entity (node: 1574) cannot be referenced."
    – J.g
    Commented Jun 11, 2021 at 20:23
  • I've never encountered that error. You need to update your question with all the information.
    – prkos
    Commented Jun 12, 2021 at 0:01

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.