I've been researching this for the last few days and I cant find a clear explanation of this issue im facing. I'm receiving an error when a node has an empty collection with no values.
The collection field: field_window_shade
The fields within the collection: field_question, field_answer
Here is my code that is only looping thru the collection array within my node.tpl:
$wrapper = entity_metadata_wrapper('node', $node);
$formtype = field_get_items('node', $node, 'field_window_shade');
foreach($formtype as $itemid) {
$item = field_collection_field_get_entity($itemid);
print $item->field_question['und'][0]['value'];
print $item->field_answer['und'][0]['value'];
}
I am after something like this:
$wrapper = entity_metadata_wrapper('node', $node);
$formtype = field_get_items('node', $node, 'field_window_shade');
if (isset($wrapper->field_question)) {
foreach($formtype as $itemid) {
$item = field_collection_field_get_entity($itemid);
print $item->field_question['und'][0]['value'];
print $item->field_answer['und'][0]['value'];
}
}
I've seen this question asked about 5 different times with 10 different solutions and I can't seem to reach a solution here.
Thank you !