0

I have a content type A which has a node reference to another node (type B). I want to create a block (using views) to display the content of that node reference in a side block on its respective node page (type B).

I think this might be possible with either contextual filters or relationships, but as I have never used either, I'm not sure exactly how to do this. If I could use these, I imagine that I could use the url as a filter.

2

You can do that by creating a view of Type A and than adding a relationship with Type B as following:

  • Create a view of content type A and choose it to be of fields type.
  • Add contextual filter for node id. (This will play a major role to filter out the content on the basis of argument [nodeid] you will be entering)
  • Add relationship with content type B. (Entity Reference: Type B)
  • Now add the fields for Type B (and apply the relationship with the Type B).

enter image description here

  • I don't see Entity Reference listed in the relationship section – user1015214 Oct 10 '13 at 14:59
  • @user1015214 If you added the entity reference in your content type than for sure it must be listed in the entity reference list, check if the name me different like if the name of entity reference is product than the name you may find in the reference list may "related product" or like so. – Ankit Agrawal Oct 10 '13 at 15:05
  • My field is a node reference field. But I don't even see Entity Reference in the filter dropdown. Do I need another module to be enabled first? – user1015214 Oct 10 '13 at 15:10
  • @user1015214 You need to install the entity reference module: drupal.org/project/entityreference , than you can find the entity reference in the drop down, it will best to use entity reference as entities are fieldable and can easily be reference with other entities – Ankit Agrawal Oct 10 '13 at 15:12
  • I have installed this module and flushed the cache, and still don't see it as one of the dropdown filters. – user1015214 Oct 10 '13 at 15:24
2

I am assuming, you have a node of type A, that refers to a node of type B through a node referance field "field_noderef" attached to node A. You want to display the details of node A when you visit node B.

  1. Create a block type view. Filter as content type = A
  2. Create a contextual filter "field_noderef", set a default value of "get NID from URL".
  3. Display the block in node page of content type B *this part is important.
  • will this work even if I have created url alias to replace the node id? – user1015214 Oct 10 '13 at 14:42
  • yes absolutely. Alias is never a replacement to node/[nid] path. The above solution will work. – Neo Oct 10 '13 at 14:44
  • do I have to set it to fields or content format? Its not displaying anything yet. – user1015214 Oct 10 '13 at 15:07
  • modified my answer. hope that helps. If not, you need to try and grab some screenshots and share wit me so that i know where are you going wrong. – Neo Oct 10 '13 at 15:17
  • how do I share a screen shot? – user1015214 Oct 10 '13 at 15:34
0

I actually was able to get this result without Views at all. I simply did a variable set for the field I needed from inside the node template. I then created a custom block and retrieved the variable with variable_get.

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.