I read through the entire issue about creating the backreference feature (#1083902: Backreferencing (listing nodes that reference the target node)), but I couldn't find any information about how to actually set up a view to display backreferenced data. And since there doesn't appear to be any documentation for this module, I'm totally stumped on how to do this.

My site has two content types: Expert and News. News nodes have a field, field_related_people, which is a node reference field which references multiple Experts. What I'd like to do with backreferences is to display on an Expert's page all the News articles upon which said Expert is referenced. Could someone please explain how to do this?


coredumperror’s picture

Status: Active » Needs review

I went ahead and did some trial and error, and finally found the solution. This video helped a lot toward my understanding of how References interacts with Views Relationships. For anyone else who might be in a similar situation, here's my solution.

These instructions are for attaching a block to each instance of CONTENT TYPE X, which lists items of CONTENT TYPE Y that have references back to the instance of X. The references are in a field called "Related X".

1. Create a new View with "Show Content of type X", which outputs a Block. Give the block an empty title.

2. Add a Contextual Filter of type "Content: Nid", with the "WHEN THE FILTER VALUE IS NOT AVAILABLE" option set to "Provide default value -> Content ID from URL".

3. Add a Relationship of type "Content: Related X (field_related_x) - reverse". Then check the "Require this relationship" option on the next page.

4. In the "FIELDS" section, click the "Content: Title" link. Set it to use the "field_related_x" relationship.

5. In the BLOCK SETTINGS, change the Block name to "X's Related Ys" (or whatever you like, since this will only appear in the admin interface). Then if you want a label for your related Ys, add a HEADER of type "Global: Unfiltered Text". Put a label like "Related Ys:" into the text area.

6. Change the PAGER option to "Display all items".

7. On the Blocks administration page (admin/structure/block), place your new "X's Related Ys" block just below the "main page content" block.

These steps have defined for you a block which displays all the Related Ys of the currently displayed node. Nodes which aren't related through a "field_related_x" field to a Y will not be given any new markup, because of the way we set up the Header, Title, and Relationship options in our View. However, if you want to be more thorough about only displaying your Block on the right content types, you'll need the Context module.

8. With the Context module installed, go to Context administration page (admin/structure/context). Click "+ Add" to add a new Context.

9. Name your Context something like "xs_ys_block" (it has to be formatted like a machine-name) and give it a good description.

10. From the "<Add a condition>" dropdown, select "Node type", then check the box for Node type X. Change the "Set on node form" option to "No".

11. From the "<Add a reaction>" dropdown, select "Blocks", then scroll down to the "views" section of the panel on the right. Check the "X's Related Ys" block, then click "+ Add" on the "Content" line to the left.

12. If "Show row weights" is visible, click it to show the row weights. Set the row weight to "10", so that this block will be placed after the "Main page content".

13. Save the context, then check out your X nodes to see their shiny new block.