views:

1410

answers:

3

I would like a page that displays a list of nodes (I can do this part with the Views module) and then also displays the details of a single node below the list. Ideally the details will update via Ajax when a node in the list is clicked, but reloading the page would be fine for a start.

I'm just starting to get into Drupal and the number of levels at which I can do stuff is somewhat overwhelming. For example should this be a View page with a customised block at the bottom? A page with two blocks (one for the list one for the item)? If so how would they communicate the node ID? Is there already a module that will do this for me? Maybe I should write my own module? And so on. If anyone with a better general understanding of Drupal could point me in the right direction it would be appreciated.

Edit: Thanks for the answers so far, I think they point out that I missed out an important detail in my original question though. So, some more details:

I would like this page to effectively be a user's home page. As such my view is restricted to showing nodes that they've created. Editing the default node page would give me the problem of which node to send the user to when they log in (which may be possible I guess) and also would mean that I presumably couldn't view the node without also seeing the view?

I have been trying another tack which is to create page node which includes the View (called user_home) using some PHP. I have also set the View control to create a link for each node in the list and include the node id in that link e.g. http://localhost/drupal-6.10/?q=node/13/12 (where 13 is the node ID of the page I have created and 12 is the node ID of the item in the list).

<?php
//output the user_home view
print views_embed_view('user_home', $display_id = 'default');
?>
<br/>
<hr/>
<br/>
<?php
$queryparam = $_GET["q"];
// find the second /
$index = strpos($queryparam, '/');
$index = strpos($queryparam, '/', $index + 1);
$displayNodeId = substr($queryparam, $index + 1);
$displayNodeId = (int)$displayNodeId;

if ($displayNodeId > 0)
{
  $displayNode = node_load($displayNodeId);
  print node_view($displayNode);
}
?>

Now, this works, but I'm sure their's a more drupal friendly/compliant way of doing things (and the query string parsing is a nasty hack).

A: 

I would do that as following. Set Page specific visibility settings for your Views block with nodes list to be shown only on that nodes, Pathauto module can be helpful here also for managing bunch of nodes paths.

Maria Shaldybina
+1  A: 

The canonical solution for this is to use a block in the "content top region" and the full node in content region.

The most basic way of achieving this is to simply display the node page normally and, with a theme having the content top region (Garland doesn't, Zen classic does), create a Views block containing the list you want and place it in that region. you can use the path as the argument to the View so its contents can depend on the currently displayed node. Then, define the visibility of the block to only match the conditions you want, probably to display only on node pages, or maybe on node pages of a specific content type. For this, use the PHP visibility mode for the block, and do something like

// Filter args for safety
if ((arg(0) == 'node') && is_numeric(arg(1)) {
  $node = node_load(arg(1);
  return is_object($node) && ($node->type == 'the_content_type_i_want');
}
else {
  return FALSE;
}

That way the block will be displayed only when you want it.

If your theme does not have this feature, Panels provide a way for you to divide the page and place the view in one panel and the full node in an other one.

FGM

related questions