3

If you have for example http://www.example.com/node/5 and you go to that node page you get the page created by Drupal. My node is about an organization and I want on the bottom of that page a list with all the employees. Is there a way that I can do this with the views module?

Because I don't want to use PHP or HTML in the file for that. I know how to create a new view but if I create a new one I cannot use the same page link.

I think that this is a common problem but can't find a solution.

  • Hi and welcome to Drupal Answers. What are employees for Drupal? Nodes? Users? Could you please clarify. – Wtower Dec 15 '14 at 9:19
  • For this example I just used the nodes. – Jeroen Dec 16 '14 at 15:30
4

Whatever your employees are, if you can create a view of them (and you say you can), you can use Viewfield module.

Viewfield provides a field that holds a reference to a View and renders it whenever the entity containing the field is displayed.

Exactly what you want to do, without any snippets of PHP.

Specifically, you need to use this capability:

  • Administrators may supply a common value that will be used for all entities in a content type.

Just set viewvield to display "employees" view for all organization nodes, and filter views by whatever association between employees and organizations you created, using contextual filters.

Viewfield has built-in passing mechanism, token-based on node / content type configuration side. It can pass node id, author, creation date and any field value you have. On the Views side, these will be contextual arguments as usual.

Benefit over blocks: it will work no matter how and where node is displayed - display configurable just as any other field. You don't need do care to alter block configuration if you want, for example, change path from /node/50 to /organization/drupalangels. Blocks may get left behind. Viewfield will simply continue to work. Also, you can place it directly between other fields without any problem, should the need arise.

Of course for each his own, Viewfield is not flawless either. Blocks was always faster for me to configure, for example. And bit easier to theme. I just found the bit of extra time at first configuration worth it in the long run. For short and fast project, for a client that does not pay well and don't want you to manage site after it's done, it might be not worth to bother.

|improve this answer|||||
  • Viewsfield would require you to add a view specifically to each organisation node. Using Viewsfield is a good suggestion if Jeroen would like a different type of view for some/all organisations. I had assumed that he has multiple organisation nodes that would need the same view. – autopoietic Dec 15 '14 at 9:32
  • @autopoietic viewfield can have one view configured on all nodes of certain type, filtered using parent node content - without any viewfield eiditing available to node author or editor. – Mołot Dec 15 '14 at 9:34
  • I did not know that. Useful information, thanks @molot. What advantage would viewfield have over standard drupal views block? Would it be able to pass nid? – autopoietic Dec 15 '14 at 9:37
  • @autopoietic it has built-in passing mechanism, token-based on node / content type configuration side. It can pass node id, author, creation date and any field value you have. On the Views side, these will be contextual arguments as usual. Benefit: it will work no matter how and where node is displayed. You don't need do care to alter block configuration if you want, for example, change path from /node/50 to organization/drupalangels. Blocks may get left behind. Viewfield will just work. – Mołot Dec 15 '14 at 9:40
  • Thanks Molot, there are many places I could use that. I normally avoid installing extra modules where core (&views) would suffice, but this approach seems to have some clear benedits, as you have described (hence 21,275+ sites using module) – autopoietic Dec 15 '14 at 9:43
3

You can create a block display for your view and display it in the content region of that page (below main content). Specify the path of the page in the block configuration to have it appear just on that page.

If your node is one of many organisation nodes, you will want to pass information about which organisation is being displayed to the block so that it shows only employees related to that organisation. If this is the case, add a Contextual Filter to the view which takes a default argument from the url (the node id).

|improve this answer|||||

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.