Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer
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 '12 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 '12 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 '12 at 5:36

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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