4

I have one field collection with 4 fields. How to get the data of field collection in views tpl file

I am trying to load data as

field_collection = entity_load('field_collection_item', array($node->field_suppliers_value['und'][0]['value']));
print_r($field_collection);

The fields in field collection are one is text field and another one is entity reference and one more is term reference and last one is date type.

I am able to retrieve the data only for text data type and for other data types it was showing as [target_id]=some number.

How can i retrieve the data for other data types except text.

  • Your approach is correct. I would recommend to use dpm($field_collection) (a function bundled with devel module) to inspect the object. It even gives you the PHP expression needed to load any particular item from the object / array. – W.M. Apr 15 '16 at 11:13
2

These are the field data types and their column names:

  • Text - value
  • Entity Reference - target_id
  • Term Reference - tid

Combine that with field_get_items(), e.g.:

$items = field_get_items('node', $node, 'field_suppliers_value');

if ($items) {
  // Or $items[0]['target_id'], etc
  $fc = field_collection_item_load($items[0]['value']);
}

Hopefully that'll give you enough to go on.

  • In $fc i can see the target_id with some number, how can i get the data for that target_id. Please can you clarify me...If i print the $fc , the field array is like [field_technology_supplier] => Array ( [und] => Array ( [0] => Array ( [target_id] => 19417 ) ) ) – user3686276 Apr 15 '16 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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