tags:

views:

65

answers:

1

I have a new content type called 'A' which has a cck reference node field that makes reference to type 'B'.

I have a custom template that renders out all node types 'B' in a very specific way.. the problem is that for this template, I need to know who the current node belongs to.

type B will always have a parent (of type 'A').. but I have no way to know the nid of the parent.

Is this possible?

So in short, when $node->type == 'B' print $node->parent->nid???????????? how can this be done?

+1  A: 

Old Solution: Try using the http://drupal.org/project/cnr (Corresponding Node References) Module. This way you will be able to find out the "parent" of Node B. Basically you will get a node reference field in Node of type B that points back to a Node of type A (the "parent" node). Also you will only need to update one of the Node Reference fields -- the other will be kept in sync automatically.

Alternate and Better Solution

Try using the Node Referer Module. See http://drupal.org/node/431308

Sid NoParrots
I've installed the module, however the configuration screen only gives limited instructions with no actual configuration options to admin. Is this right?
Mike
Nevermind.. I figured that out. .However the issue now is that it doesn't automatically update existing content without applying a patch.
Mike
Is there really no easy way to reference back to the parent?
Mike
@Mike: Try Node Referrer Module out. That might be better perhaps?
Sid NoParrots
@NoParrots: thanks, that worked out great.
Mike
@NoParrots: Is there a better way of retrieving the nid? $nid = $node->field_prodcut_group_parent[0]['items'][0]['nid'];Sorry I'm very new to drupal, but have some tight deadlines to meet for work!
Mike
@Mike: BTW noticed, you're new to this site -- if you think my answer was correct then don't forget to indicate that by checking on the tickmark :-) !
Sid NoParrots
@Mike: Yes, `$nid = $node->field_prodcut_group_parent[0]['items'][0]['nid']` looks correct to me
Sid NoParrots
@NoParrots: sorry! totally forgot about that.. it's checked now.
Mike
@NoParrots: that does work to get the nid, but is there a more elegant solution? That seems kind of sloppy. Thanks again though, this has really helped in overall development.
Mike
@Mike: Drupal's use of nested arrays everywhere can look ugly. Is there a way you can just have a node reference from B->A *only* instead of the other way around? That avoids all this. Unfortunately I don't know of an elegant solution to this problem apart from the use of Node Referrer.
Sid NoParrots

related questions