1

Let's say I have a Region content type that have multiple entity reference to a City content Type.

When I'm on a City page, I would like to display Cities of the same Region as the City page.

How can I achieve this through a view?

Keeping in mind that I also need to display cities of a Region at some point, switching the relation owner (City having the entity reference field to Region) might no be a solution here.

1
  • Can't you just run your own query?
    – GwenM
    Feb 5, 2016 at 22:00

1 Answer 1

0

If it was me, I'd probably use a Region reference on the City so that you only need a single-value field, but this should be quickly accomplished in Views either way.

Assuming a City reference on the Region:

  1. Create a View of Content entities of type City with a Block Display.
  2. Add a Node ID Contextual Filter with Default Actions set to Provide Default Value > Content ID from URL.
  3. Add a required Relationship to Region/Content using your reference field.
  4. Add your reference Field to the display using the Relationship and uncheck/disable Multiple Field Settings > Display all values in the same row.
  5. Add a Contextual Filter for your reference field using the Relationship with Default Actions set to Provide Default Value > Content ID from URL. Then check/enable the More > Exclude option.

Now just place the block in a theme region on your site so that it shows up on the City page. #1-4 should get a View showing all Cities that share a Region with the current one. #5 should remove the current one from the results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.