Hello,

I understand how to print node content in custom templates. However, I am not finding any docs on printing fields from parent nodes.

My_node has a parent (my_parent_node) using Entity Reference module. I want to print some fields from 'my_parent_node' in the template for in node-my_node.tpl.php.

Would this be as simple as print $field_my_parent_node_field[0]['value'] ??

Any help is greatly appreciated.

T

Comments

webdrips’s picture

$parent = field_get_items('node', $node, 'field_my_parent_node'); 
$parent_nid = $relatedPackage[0]['target_id'];
$parent_node = node_load($parent_nid);

The $parent_node object will contain all the parent information you can use in whatever manner you desire.

Looking to Migrate from Drupal 6/7 to Drupal 10/11? Have a look at our Drupal 11 demo site and request access.

redtray’s picture

Many thanks!