1

I'm trying to generate a block that looks like this in Drupal 7 Views 3:


  • Parent Node (fields)
    • Child Node 1 (fields)
    • Child Node 2 (fields)
    • Child Node 3 (fields)
    • ...

Parent node is a different content type than child node. For the time being, I've added a matching taxonomy field to the two content types. So to potentially establish a relationship, this value would be the same.

What is the best way to achieve this? It seems like a simple enough goal that Views should be able to handle. I prefer to thoroughly understand the core software w/ Views, before I blindly install a bunch of modules that I may not need.

  • More information is needed. Tagging the nodes with the same term does not setup a parent/child relationship. Are they child pages because of their position in the menu structure? – jsheffers Mar 5 '13 at 21:18
  • I'm not sure what information you would like. I haven't done anything yet, aside from set a taxonomy term field for each content type to establish a foreign key, but I haven't attempted to utilize this in any way yet - sorry to cause confusion. I'm basically just looking for a best-practice, or even some general advice as to how to accomplish this. – cshontz Mar 5 '13 at 21:31
  • Well first off, you need one of two things. They have to be designated as child pages by adding them to the menu, or you need to add a node reference field (drupal.org/project/references) so you can relate the children pages to there parent. I would start there. – jsheffers Mar 5 '13 at 21:33
  • Let's take a step back - I'm trying to create a data model for an event calendar. It has a few parent fields: calendar title, calendar description, and events - where events is an array of events each with their own fields. I'm trying to put this in terms of Drupal, and display it in a block. – cshontz Mar 5 '13 at 21:44
  • I've installed References and created the parent child relationships, but how do I utilize this in Views? – cshontz Mar 5 '13 at 21:52
1

I've achieved the desired output by creating a vocabulary of taxonomy terms which is essentially just a flat list of foreign keys. There is no semantic representation of a hierarchy here.

NOTE: This is a different example than the event calendar I described in the comments of my initial post, however the data model is the same.

  • Parent content type (Rich Menu) contains this taxonomy term field, in this example called "Menu".
  • Child content type (Rich Menu Item) also contains the "Menu" taxonomy term field.
  • If Rich Menu Item is a child of Rich Menu, the two term fields are set to match. NOTE: I wonder if this idea can be simplified using node references (References module) instead of taxonomy.

Then I created a new block view called "Rich Section Menu". This block will display the parent content type, Rich Menu, filtered by the taxonomy term from the field "Menu" (value = Section). Create an attachment to be displayed after the block which will render a list of children from the Rich Menu Item content type. The child content type will also be filtered by the Menu term field (value = Section). NOTE: Adding the relational term field to the list of filters is only necessary if you expect to have multiple parent/child relationships that share the same content types.

Tried to post screenshots of my Views configuration for clarity, but my reputation isn't high enough.

This achieves the output I desire, however it's a bit simplistic. I would prefer to create a semantically correct parent/child hierarchy using taxonomy or node references, and have Views render that output in a single block, without an attachment, with support for children more than one level deep.

So this works, but is there any way that I can do it better?

| 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.