0

I have two content types, "Contributor" and "Story".

Contributor has the following fields
1. Default title/label
2. Job title
3. Email address

Story has many fields, but includes an Entity Reference field that accepts multiple Contributor nodes.

When viewing a Story node webpage, I would like to have the "contributors" entity reference field to be displayed within the right sidebar using a views block. It should output all contributors that have been related to this Story node.

I have attempted to create a views block of Contributor nodes using Contextual Filters, but have not been able to output the contributors related to that story node. Are contextual filters the right method or should I have Relationships configured as well? If I have not set any contextual filters, all of the Contributor nodes are listed, but I can't seem to figure out which contextual filter and settings to use.

1

Just coming from memory I would recommend something like this:

  1. Create a view of what you want to show. (In your case, a view of content-type="contributors")
  2. Create a relationship in that view to the content that contains the reference field. (Just click on add a relationship, and search for the name of your reference field)
  3. Create a contextual filter to filter by ID. This filter will also be the reference field name. (choose "Provide default value" then "Content ID from URL") This contextual filter will use your relationship.
  4. Restrict that Views block to only show on that content type (in block settings of course).

What you're doing is adding a relationship to that reference field. Then it is available as a contextual filter, where you can then provide a default value to filter by content ID.

Note: keep in mind if ever your reference field is not available as a relationship in your view, you may need to first add a content or node based relationship.

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.