Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Installation and Setup for Node Reference View

Parent Feed: 

The Node Reference module defines a field type for use by the Content Creation Kit (CCK) to reference one node from another. It works very good and allows you to add a greater amount of complexity to your site. The only problem with the Node Reference module is that the default display options for the referenced node field are very limited. But thanks to the Node Reference Views module, you can use all the formatting power of the Views module to display your referenced node field.

An often used example of when to use this module is for creating a music library listing using CCK: Content types are created for the albums and the songs, then Node Reference is used to relate the songs to their respective albums. For this example we will have a content type called Album with text fields for title, year, artist and a content type called Song with a simple text title and a node refernce field to relate the song to the Album called field_album_reference. From here, I will give quick setup instructions to get you going with the Node Reference Views module:

  1. Prerequisites

    Before you begin, you should have the following modules installed:

    Content - http://drupal.org/project/cck
    Node Reference - included with the Content module
    Option Widget - included with the Content module
    Text - included with the Content module
    Views - http://drupal.org/project/views
    Views UI - included with the Views module

    Additionally, you should setup the above described songs and albums content types or have a set of content types connected by a node reference field.

  2. Download and Install Node Reference Views Module

    Node Reference Views - http://drupal.org/project/nodereference_views

    Once you have downloaded the module, move it to the appropriate modules folder for your install and extract it in place. From the Modules page (Administer > Site building > Modules), enable the Node Reference Views module.

  3. Clone and Re-Name Preinstalled View

    From the views administration page (Administer > Site building > Views) enable the view entitled field_noderef_example after reading the brief description/instructions. Now on this newly enabled view choose clone. The most important thing to rember with this setup is to rename this cloned view to have the exact same name as your node reference field, in our eample this is field_album_reference. Fill in the view description and the view tag with something that will help you remember what this view is, and then choose next.

    Modify the view by choosing additional fields from the referenced node to be displayed as well as modifying most of the rest of the view settings to suit your needs. Do not change the arguments field. Finally, Save the view.

  4. Disable Preinstalled View

    From the views administration page (Administer > Site building > Views) disable the previously enabled the view entitled field_noderef_example.

  5. Edit the Display of your Node Reference Field

    Edit your content type (Administer > Content management > Content types) that contains your node reference field. From the tabs choose Display Fields. Choose view from pulldown on your node reference field, in our example it would be the Album field.

    Now when you view your song nodes, the Album field will appear as the view you previously described. Nice. It can be styled like any other view can be.

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web