I have been trying to learn the ins and outs of hooks and basic theming in Drupal.
I currently have a template file for one of my content type (node--opportunities.tpl.p
hp). Everything has been going great theming with this except for a field collection that I am now stuck on. I know there are a multiple ways of theming a field collection and this is the worse. But I can't figure it out when the array is perfectly right in front of me.
field_services
is the field name. When I dsm($content)
on the node you can see it perfectly. So I'm using a foreach to loop through the items, pull them out and load them. Then print their values with my markup. But it will not render. Even when I 'dsm' the final array, it shows me my fields perfectly. But when I try to render them, nothing happens.
Can anyone help me understand what I am doing wrong? I am more interested in why my investigative attempts to print the values of this array are fruitless than I am interested in actually theming the field collection.
hide($content['field_services']);
//horizontal radios
print '<div class="ec-controls">';
print render($content['field_opportunity_type']);
print '</div>';
//if (!empty($content['field_services'])) {
print '<div class="ec-collection">';
foreach ($content['field_services']['#items'] as $entity_uri) {
$a_field_collection_item = entity_load('field_collection_item', $entity_uri);
foreach ($a_field_collection_item as $a_field_collection_item_object ) {
dsm($a_field_collection_item_object);
print render($a_field_collection_item->field_service);
print render($a_field_collection_item_object->field_service_multiplier);
print render($a_field_collection_item_object->field_extend_service_total);
//print render($a_field_collection_item_object->field_service['und'][0]);
//$...->field_service['und'][0]['entity']->field_unit_price
//->field_service['und'][0]
}
}
print '</div>' . "\n";
//}
I've also tried these as suggested with no luck. Here is also a printscreen of the dpm
:
DPM PS http://ecteam.net/Untitled.png
dpm($a_field_collection_item_object);
print 'test';
print $a_field_collection_item->field_service['und'][0];
print $a_field_collection_item->field_service['und'][0]['entity']->title;
print $a_field_collection_item->field_service['und'][0]['target_id'];
print $a_field_collection_item->field_service_multiplier['und'][0]['value'];
print $a_field_collection_item->field_service_multiplier['und'][0]['value'];
print $a_field_collection_item->field_extend_service_total['und'][0]['value'];
Note: field_services
is the parent field collection, field_service
is the individual field that contains the service title that I am trying to render from it.
field_services
is the field name, your code is usingfield_service
.