How can I print the rendered values of an entity reference field into node.tpl.php?

I have an entity reference field called Instructors which references users. Using Devel I can find the target_id of entity reference items, but I can't for the life of me figure out how to render these ids.

1 Answer 1


You can try something like this

// $node represents the node object
$wrapper = entity_metadata_wrapper('node', $node);
$instructors = $wrapper->field_instructor->value();

Now in instructors you will have each instructor user object and you can print what ever information you want to print from it.

  • Since I'm using an entity reference field, would it be possible to use the method you suggest to render the final output as a link to the entity, or would I have to construct the link myself?
    – filmoreha
    Sep 22, 2012 at 3:27
  • The above method is dependent on entity api which is required by the entity reference module. you can use a foreach loop on the instructors array and print the values.
    – junedkazi
    Sep 22, 2012 at 3:31
  • Alright, after messing with it for a bit I finally came up with a solution. Did need to use foreach ($wrapper->field_instructor->value() as $i) to get to property values. Then created an array links from the uid and name properties and finally imploded the array for printing. Took a bit of experimenting and trial and error on my part, but thanks for the tip off!
    – filmoreha
    Sep 22, 2012 at 5:36

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.