Hi folks.
I'm having a bit of a head-scratcher on the issue of pulling individual items from a field collection, specifically in a views field template.
I can do it on a node display just fine.

here's the scenario:
I have a field collection called "field_speaker_info". This field collection has "field_speaker_name", "field_speaker_affiliation", and "field_speaker_bio".
I need to display these separately in various views.

On the node display, this is straightforward.
Since I have an unknown number of instances of the field collection on my nodes, I loop through them thus:

$items = field_get_items('node', $node, 'field_speaker_info');
foreach ($items as $item) {
 $fc = field_collection_field_get_entity($item);
 print("<h2>" . $fc->field_speaker_name[$node->language][0]['value'] . "</h2>");
}

But of course this doesn't work on my views field template, which is based on views-view-fields.tpl.php. For one thing, this template has no $node object.
I'm thinking I need to rewrite $items = field_get_items('node', $node, 'field_speaker_info');
but doing $items = field_get_items('field', $fields, 'field_speaker_info'); fails quietly.

Any tips appreciated.

UPDATE -
I solved this by getting the nid that the views row's content came from using $row->nid:

  $theNID = $row->nid;
  $loaded = node_load($theNID);

Now I can do $items = field_get_items('node', $loaded, 'field_speaker_info');
and walk through the $items set as before

Comments

krrishnajee’s picture

Great! it works.