views:

910

answers:

2

I have a node (node a) with which various other nodes (node b/c/d/e) references.

I can create a view with an argument as the node I'm viewing, (node a), and get a list of the nodes that are referencing that node.

Basically on node a viewing a list of node b-e.

I want to create a views page just for the node references of that node. But how can I pass on the argument to the new page?

Thanks.

Edit: I apologize for the confusing question.

Basically I have a movie node. I have many reviews referencing the movie node.

On the movie node I use argument: content: review_of to get a listing of reviews for that movie.

This is great, but because on the movie node there's only a few reviews, I need a page where I can see all the reviews per that movie. The question is passing on the argument for the movie from the view block (say, 3 reviews for the movie) to a view page (with all the reviews).

Ideally the url for the views page would be: /movies/movie-name/reviews

I have tried this with relationships as in Owen's answer, but was not able to make this work.

+2  A: 

If I understand what you're saying, you're wanting to create a Views page that allows you to view nodes associated with a parent node (via a CCK Node Reference field)?

Once you setup your View, you can just pass the nid (or title, or whatever field you choose as your argument), to the URL.

So, assuming you have a Views page setup at: http://yourinstall.com/related-nodes

Just pass the argument in: http://yourinstall.com/related-nodes/5

The above (assuming your relationships / arguments are correct) will show all associated nodes with NID 5.

Here's an image of the views configuration I used.

You'll note the "path" setting on the views is "movies/%/reviews". I had two movies "Movie One" and "Movie Two", with a few reviews on each. You can then use http://yourinstall.com/movies/movie-one/reviews, etc... to see the titles of the reviews.

edit: Ok, so the clarification of the problem is, you have a Views block which displays a list of Reviews specific to a Movie. As well, you'd like the "more..." link to link to a Views page which display all the Reviews specific to that Movie.

This is doable via the Views admin, but does involve a bit of PHP code.

  1. Your Views block can be setup similar to the above Views page.
  2. Override your Views block Arguments (Review Of) Node: Title, and under "Action to take if argument is not present", select "Provide default argument" -> "PHP Code".
  3. The code you use is:

    if (arg(0) == 'node' && is_numeric(arg(1) ) ) {
      $node = node_load(arg(1) );
      return str_replace(' ', '-', strtolower($node->title) );
    }
    

In essence, the Views block acts the same (expects a Movie node title), but will use the code above to try pull the title from the URL (note this works fine with path aliases). The Movie node title is placed into the more link as well (see the above image) in the format "movies/[movie-title]/reviews", which will link to the Views page as expected.

Owen
Thanks for that, is there any way of having the node title in the url?
Jourkey
Yep, just use the node title as the argument instead of nid. There's an option to convert spaces to dashes as well for URL purposes. I added an example into the answer.
Owen
Thanks for that, but I don't understand how this could work. My argument is not nid, but the node reference field. If I set the title as the argument, that gives me nothing. Thanks for your help.
Jourkey
Hmm, your relationship should be the node reference field, then your argument should be the node nid / title (using the relationship of the node reference field).
Owen
Thanks, still don't get it though. Even if I create a relationship, it's that doesn't filter by the nodes that reference this node. So I add an argument for the node title using the relationship. My Action to take if argument is not present: is Display all values. I used to give it default values: node id from url, but that causes it to display the (incorrect) nid. But this causes the argument to be 'all', rather than the title name. Just not sure how this is supposed to work. Thanks.
Jourkey
This is how I set this up, Filters -> Node: Type = Child, Relationships -> Content: NodeRefField, Arguments -> (Parent) Node: Title, Fields -> Node: Title (so we can see at least the title of the related nodes). Under relationships, "require this relationship". In addition, I use "display empty text" in the argument, so passing the title through the URL will only show associated nodes, or none at all.
Owen
I created my view with your configurations, it does not work for me. The 'more' link on the block sets the argument as 'all', rather than the node title. The argument is not passed on AFAIK. I clarified the question in the question.
Jourkey
I am surprised that this works for you. Please try adding a block display with a more link. My more link goes to movies/all/review. Also, nothing shows in the block itself. Manually inputting the node title between movies and review only returns me to the movie node's page, rather than a review view. Are you SURE this works? I can't imagine how drupal would know *which* node is being referred to just from a node title, because multiple nodes can have the same title! (but not the same id). Thanks for all your help!
Jourkey
Ah ok, I didn't get that you had a block already and were trying to modify the more link. That needs a bit more finesse if you want to stay within the Drupal admin. I'll update my answer accordingly.
Owen
Oh this works! I think the reason why it wasn't working before was because of the suburl path alias module. Thanks a LOT!
Jourkey
Great! Glad you got it working.
Owen
A: 

Am I understand this problem correctly?

The real problem is that the "more" link in the block doesn't link to the proper view?

In other words, If your view is "movie_reviews", and on the movie node page you have: movie_reviews->block added on the side, within this movie_reviews->block the "more" link directs visitors to movies/all/reviews ?

Have you considered templating these changes? (manipulating the link within the block to work with the node of the currently being viewed movie node.) Blocks are very easy to theme.

I can give references on how to implement something like this if I this makes sense for your site.

electblake