I've been playing around with this for the better part of a few days now with no luck. Here is my Collection data:
Collection name: field_video_collection
Within the collection there is a field called: field_video_file_col
My fields print fine in my custom field-collection-item--field_video_collection.tpl.php
template, I followed the documentation according to this issue to get my template name and I simply print the fields as <?php print render($content['field_video_file_col']); ?>
etc... within that template.
Now for the fun part, I'd like to extract the fid
for each field_video_file_col
item in the collection in any given node and render it as a printed variable. I followed the answer in this question here on Stack but it does not seem to work for me. if I do:
print '<pre>';
var_dump(get_defined_vars());
print '</pre>';
I see I have this as part of the data available to me for field_video_file_col
["field_video_file_col"]=>
array(1) {
["und"]=>
array(1) {
[0]=>
array(12) {
["fid"]=>
string(3) "888"
So it looks to me that the FID is 888 in this case and I want to render that in my template. My node preprocess function is as such:
function MYTHEME_preprocess_node(&$vars, $hook) {
$entity_type = 'field_collection_item';
$bundle_name = 'field_field_video_collection'; // Field name the collection is attached to
$field_name = 'field_video_file_col'; // Field name within the field collection
$video_file_fid = field_info_instance($entity_type, $field_name, $bundle_name);
if ($video_file_fid) {
$my_fid = $video_file_fid['fid'];
}
}
The end result needed is that I need to render the variable in my field-collection-item--field_video_collection.tpl.php template as:
<?php print $video_file_fid; ?>
... but this does not seem to work. I've searched all over and tried many different incarnations of this code and combinations but still no joy.