Views in the context of a node

Events happening in the community are now at Drupal community events on www.drupal.org.
kirilius's picture

Hi there,

I posted this question in the main Drupal forum but maybe this group is the right place for it.

Here is the situation:

I have a view defined that shows some information relevant/dependent on the context of a node. In my case I am using the view to show some related nodes to the main one.
Let's say the URL is http://mysite/views/show_more_data/[nid]
There is one parameter that is the node ID of the node we want to display more info about. This view works fine when called through the URL (a page view).

My question is: what are the best ways of integrating this view into the node display so that the context (the node ID) is automatically passed to the view?

Some ideas I have and the problems I cannot resolve:

1) Somehow nest the view contents directly in the full node display
- How can I do this?
- How can I pass the correct node ID to the view in this case?

2) Create a block view and display it on the side or below the node contents
- How to tell the block to show ONLY when a specific node type is displayed?
- Again how can I pass the correct node ID to the view in this case (how to make aware the view of the context node)?

3) Add a tab to the main-node display. I have seen this in action but I don't know how it works.
- How can I add a tab to a specific node display page?
- How to display a view in a tab?
- Again how to send the correct node ID to the view?

Same question about a view in the context of an Organic Group?

Thank you for your help!

Comments

1) In your node.tpl.php (or

merlinofchaos's picture

1) In your node.tpl.php (or more likely node-CONTENTTYPE.tpl.php) you can use theme('view') and pass array($node->nid) as the argument.

2) If set as a block, in the arguments PHP code you can do the classic trick of if

<?php
(arg(0) == 'node' && is_numeric(arg(1))) { $args = array(arg(1)); }
?>

3) Set the URL to node/$arg/some-name-to-identify-this-tab

Thanks for the quick answer.

kirilius's picture

Thanks for the quick answer. I'll try and see which one works best.

Two questions concerning (2):
- where do I put that code?
- How can I make the block appear only for my type of node? (I guess that's not related to the views to much)

...

michelle's picture

1) The arguments section of a view has a place to put in code. I think it might be in a collapsed fieldset. Look for something labeled "argument handling code" or similar.

2) See http://drupal.org/node/64135

Michelle


See my Drupal articles and tutorials or come check out life in the Coulee Regio

Thanks Michelle, it worked!

kirilius's picture

Thanks Michelle, it worked!

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: