tags:

views:

10

answers:

1

Using Drupal 6.x I have created two content types: Person and Event. Event has a custom field called Attendees (of type: Node Reference; unlimited number of values to person). When viewing a specific person how does one show all their events?

I have created a view (Personal Events) and added a block display. I enabled the block to show for content type Person. How should the view be defined? Or is there a better way?

Modules installed: CCK; Node Relationships; Views

A: 

I have an answer to my own question. However, there maybe better answers... I can only hope.

Created content block (Personal Events)

Added this code to the body of the block. This code passes the node id argument to a view

<?php
if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) {
  $node = node_load(arg(1));
  $args = array($node->nid );
  $view = views_get_view('PersonalEvents');
  print $view->preview('default', $args);
}
?>

Added this code to the Pages of the block [by selecting: Show if the following PHP code returns TRUE (PHP-mode, experts only)]... this drives the block to only appear person content.

<?php
//Read URL
$path=$_GET['q'];
//If URL is node page
if ( strpos($path,'node')===0){
//Parse URL to get nid
$links=explode("/",$_GET['q']);
$nid=$links[1];
//Load node
$node=node_load($nid);
//Display block only if node is of certain content type
if($node->type=='person'){
return TRUE;
}
}
return FALSE;
?>

Then created view with:

Style: Table

Relationship Content: Attendees (field_attendees); requires this relationship (checked); and Delta set to ALL.

Argument: Node: Nid; Relationship: Attendees; Hide view / Page not found (404) [selected]

Fields... simply selected Node Title and Date (for now)

Filter: Node Type = Event

Anyone have a better way?

clsturgeon