Antilope
Antilope

Reputation: 445

take the fields or the entire contents of a "node reference"

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)

Upvotes: 2

Views: 208

Answers (1)

Muhammad Reda
Muhammad Reda

Reputation: 27023

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.

Upvotes: 2

Related Questions