4

I have two content types called Basic Page and Contact Info.

  • There are around 5 nodes from Contact Info with some contact info (phone/fax/email/IM) in the body field.
  • In Basic Page content type there's an Entity Reference field that refers to Contact Info. So that for each page there would be a main contact person. When someone create a Basic Page node they can pick a Contact Info node from the dropdown (out of the 5 Contact Info nodes).

Basic Page -> Contact Info (Basic Page content type refers to Contact Info content type)

Then I created a block view (added to the sidebar of Basic pages) which displays the contact info associated with that node.

Added a Relationship in the view (Entity Reference: Referenced Entity)

Right now it's displaying all 5 contact info nodes, not just the one associated with that particular basic page node. I tried to tweak the Contextual filter and relationships but couldn't get it to work.

I have a feeling that the solution lies in the php code that goes in Provide default value -> php code section.

Any help appreciated. Thanks

  • 1
    What's the contextual filter filtering on? Is it grabbing the node ID by default of the Basic Page? The relationship is basically going to make available the Contact Info attached to each thing the contextual filter filters for. – Renee Jul 12 '13 at 20:42
  • I tried various different combinations for the contextual filter, but none of them were working. (It won't display any Contact Info nodes). So I removed the contextual filter. As of now it's displaying all 5 Contact Info nodes in the sidebar. I just want to know what's the correct contextual filter that I need to apply to get only the correct 1 contact info node to display. – Dhanushka Jul 12 '13 at 20:46
7

The contextual filter should be "content:nid"

The options should be set as follows...

The Relationship should be your "Entity Reference: Referenced Entity" relationship

Under "When the filter value is NOT available" check "provide default value" and select "Content ID from URL"

Apply changes and save view.

I think this is the same thing Renee was saying, just in other words.

Hope this helps - I recently lost a weekend to figuring this out ; )

  • Thanks for the reply. I tried that, but it didn't work. Here are some screenshots imgur.com/a/HoNVt – Dhanushka Jul 12 '13 at 21:27
  • Have you tried creating a Referencing Entity instead of Referenced relationship? Also, you could work around fields by setting up a content type that shows State and City. – Anne Bonham Jul 12 '13 at 21:42
  • And, how are the fields set up? The field that shows the relationship data needs to have the relationship selected. – Renee Jul 12 '13 at 21:52
  • The fields shouldn't need to refer to the relationship (leave that setting "Do not use relationship") – Anne Bonham Jul 12 '13 at 22:38
  • This explanation may help: banoodle.wordpress.com/2013/06/20/… – Anne Bonham Jul 12 '13 at 22:43

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.