0

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
  • 1
    any specific reason for using node_load in your template?
    – nikunj
    Oct 13, 2015 at 6:54

1 Answer 1

0

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;
        }
      break;
    }
  }
}

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

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

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

}
?>

OR

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

1
  • 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
    Oct 13, 2015 at 8:56

Your Answer

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

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