0

I have a content type 'projects' and a content type 'staff'. So on the projects node I have two fields that list the 'staff' nodes, 'project manager' (one staff node) and 'other people' (multiple staff nodes). So what I want to do is on the 'staff' node when this is viewed on it's own to list the projects they are involved in. Is there a way in the template to grab any project link that this person might be involved in, be it leading it or just listed?

1

I assume you are lining the nodes via Entity Reference.

In that case use Views to grab the staff node nid and show the related projects via a relationship. Add it to your staff page via a block, EVA, Display Suite, Panels or some other contrib module (there are a quite a few that can embed a View).

The exact module you choose depends on your requirements, such as what modules you already have installed, and what other features you would like from the module.

You can do it yourself in the template if you wish, but you will have to create an SQL query for that or use views_embed_view to embed the same view referred to above directly into the template as a variable via template_preprocess_node. The problem is that the list of staff is available on the project node but not the other way round. You can solve that by having a two-way reference, by using a module such as Corresponding Entity References, but to me that sounds too convoluted.

  • Hi, thanks for your answer sounds like what I want. Yeah with Entity Reference. So I create a view for the staff, unsure what you mean by get the nid, well I get what you mean so the node id is how you link it. But if you want this to be on the node pages themselves then how do you pass the node id in for each node... If that makes sense? – karl Dec 17 '15 at 12:10
  • fabulous, took a bit of time but got my head around these relationships now I think, much thanks! – karl Dec 17 '15 at 17:10

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.