Sharing the Code

Programming stuff that might be useful to others

Referencing child documents from another document in Drupal 6

Sometimes in Drupal you need a repeating item linked to a document. It might be a number of images for a image gallery. Most of the time using a CCK field and setting the number of values to unlimited does the trick. But sometimes that linked item has itself a number of fields. For example below I have a video gallery where each video has a title, description and a YouTube video ID:

The way to deal with this is to use node reference fields which is part of the core CCK module. You will also need to install node reference views module. You will create 2 views, one view will be for selecting the child nodes when you are editing the document and the other will be when you are presenting those child nodes on the frontend website. Of course you will also need to theme the second view.

Below is an example of the first “editing” view:

The name of the second “frontend” view needs to be the name of the field e.g. field_media_items:

In your referenced node type you might have an order field so you can control the order they are displayed on the frontend website by adding a sort criteria in the view.

Next you add a node reference field to your “parent” document. Select the widget you want to use whether that be a select list or checkboxes. Then select which node types you want to reference and also select the “editing” view you created earlier for selecting the nodes when editing the document:

So when you edit a document your select list will look something like this:

Comments are closed