I have a node.tpl.php file where I need to output a field from an entity referenced via the entity module (a reference field). I have tried using:

print render($content['field_parent']['#items'][0]['entity']->field_main_image);

but nothing appears! I also tried this way:

$parent = node_load($node->field_parent['und'][0]['target_id']);
print render($parent->field_main_image);

I just would like to render() a related field just as I do with $content fields.

Any hints ? Thank you

  • How are you getting your $node object?
    – Alex Gill
    Commented Jul 3, 2012 at 9:20
  • it comes as a default variable from drupal core Commented Jul 4, 2012 at 10:14
  • I mean would help to show it in your code. Have you tried a var dump of $node to see if you are getting any data?
    – Alex Gill
    Commented Jul 4, 2012 at 10:16

3 Answers 3


You can use https://www.drupal.org/project/inline_entity_display to do that with entity reference and field collection field.


You can't render the member variable of a node directly. In a frist step you have to bring it in a renderable from (array):

//returns the field in the correct language
$field_parent = field_get_items('node', $node, 'field_parent');

//retruns an array which you can render
$render_array = field_view_value('node', $node, 'field_parent', $field_parent [0]);

print render ($render_array);

Here's the differents between the two structures of these arrays. The array in the member variable of $node looks like:

array(1) {
  array(1) {
    array(3) {
      string(15) "Your value"
      string(15) "Your value"

A renderable array (for a textfield) looks like that:

array(2) {
  string(18) "Your value"
$parent = node_load($node->field_parent['und'][0]['target_id']);
print render($parent->field_main_image);

should work as

$parent = node_load($node->field_parent['und'][0]['target_id']);
print drupal_render(field_view_field('node', $parent, 'field_main_image', 'displayname'));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.