I have a field collection with adding multiple items. In each item there is an entity reference field with multi-selection of contents. I can render entity reference content by target_id using node_load in an entity_reference field template. But it is getting only first value of each item.

How can I render all contents of each item from field collection? Is there another way to fetch?

  • 1
    any specific reason for using node_load in your template?
    – nikunj
    Commented Oct 13, 2015 at 6:54

1 Answer 1


Paste the below code template.php;

function mytheme_preprocess_node(&$variables) {
  if(isset($variables['node']))   {
    switch ($variables['node']->type) {
      case "value":
        $var_abc = $variables['node']->field_abc;

        foreach ($var_abc['und'] as $key => $value) {
          $variables['abc_fields'][] = $value;

Paste the below code to create separate node tpl for that specific content type;

foreach($variables['abc_fields'] as $key => $value) {

  $var_authorvalue = $value['node']->field_author;
  //echo "<pre>";
  $var_fields = $value['node'];
  print render($var_fields->title)."<br/>";
  print render($var_authorvalue['und'][0]['value'])."<br/>";



Check How can I print a field from a referenced entity in my theme?

  • Thanks adi for reply! But in my case, i can't create node template, I want to get entity-reference data into my field template.
    – Reshma
    Commented Oct 13, 2015 at 8:56

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.