How can use the currently displayed node to filter a block-level view on that node's page?

Posted by Deane on Stack Overflow See other posts from Stack Overflow or by Deane
Published on 2010-03-08T00:35:30Z Indexed on 2010/03/08 3:30 UTC
Read the original article Hit count: 330

Filed under:
|

I have parent/child relationship set up via Node Reference. A Child record can have a Parent record selected from a Node Reference field (this is optional -- I can have Parent-less Children as well).

I've created a Views block to appear on the Parent pages, below the content. It's going to show a table of all the Child nodes for that Parent. Problem is, right now it shows every Child node. I need to filter it for just the Parent being displayed.

What I need to be able to do is add a filter to this View to effectively say, "Only show the Child nodes that are assigned to the Parent being displayed on this page."

So, somehow I need to be able to get the Nid of the currently displaying node (which will be a Parent, in all cases when this block is displayed), and use that in a filter in my View.

How exactly can I do this?

(Initially I used an attachment view for this (as this page instructs). I created a page view to display the Parent, then an attachment view to display all the Children, then attached that under the page view. This worked, but it was almost absurdly complicated to set up, and it was an undesirable for a number of other reasons -- primarily that my Parent now has two dedicated URLs, it's own node-level page, and the similar page created by this view.)

Using Drupal 6.15.

© Stack Overflow or respective owner

Related posts about drupal

Related posts about drupal-views