2

I created a content type: "battle" in which a field is a "node reference" that refers to an existing content from another content type("facts").

Now, when I go to thematize the node: "node--battaglia.tpl.php", how do I get some of the fields of the node referenced("facts"), or to use all of its contents?

(I use Drupal 7)

Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
Antilope
  • 443
  • 2
  • 6
  • 17

1 Answers1

2

Try something similar to:

$nids = array();
foreach($content['YOUR_FIELD_NAME']['#items'] as $key => $val)
{
    $nids[] = $val['target_id'];
}
// the referenced nodes ids are now stored inside "$nids" array.
// You can do whatever you need to do from there.
// below I try to load the node object of each nid.
$nodes = node_load_multiple($nids);

Hope this helps... Muhammad.

Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
  • the field "YOUR_FIELD_NAME" is located inside of another content type ... is the node selected in the field "node reference" – Antilope Nov 06 '12 at 12:16
  • Can you provide a better explanation for the issue? – Muhammad Reda Nov 06 '12 at 12:19
  • yes, I want it with php, get some fields that are not within my content type but in the content type pointed to by "node reference" (this field is the only internal to my content type) – Antilope Nov 06 '12 at 12:45