Display content on referenced node

When I create new content, I want to be able to type what page it is to display on and NOT have to create new blocks for each page (which would have gotten very tedious and out of control).  Using views and a custom content type with a node reference field, I was able to do just that.

It would have been easy to reference the NID from the URL using Views arguments, but I have Pathauto enabled and URL aliases for just about everything.

This article has been very helpful in coming up with a workaround.

Here is my quick explanation, in hopes that it might help someone else figure this out:

  1. Create a new content type with a node reference field (I used auto complete).
  2. Create a few nodes of that content type for testing.
  3. Create a new view, and add a filter for nodes of your new content type.
  4. In the view, add a relationship to the node reference field that belongs to your new content type.
  5. In the view, create an argument with these params:
    -Relationship: The one you just created.
    -Action to take if argument is not present: Provide default argument.
    -Provide default argument options: Node ID from URL
    -Validator options: Select ‘PHP Code’ and add the code from this site (which sets the argument to the current NID, regardless of aliases).
  6. Save and test.

A few thoughts for the Drupal/Views novice:

  • I’m still not quite certain what relationship is for, other than to offer something to test against in arguments.
  • Argument tests against defined parameters (current URL, PHP code, etc.) to decide what content to show.

And a side note, I did this on Drupal 7 with Views 2.

I’m a big fan of Hipporemote and Grooveshark, but was unable to find a profile already made.  In any case, I thought I’d share what I threw together.

You’ll need the keySharky plugin for Chrome.

Download Grooveshark profile for Hipporemote.

NOTE:  The artwork was thrown together pretty quickly, and you’ll see some missing captions.  Also, the images have not been updated for iPad.

Grooveshark Playpad for Hipporemote