Drupal - Can I access node ID of the parent node of a field collection field in field-collection-item--FIELD_NAME.tpl.php

Load the field collection using entity_load by passing the entity id. It gives you object where you can get the Host entity of the loaded entity. example profile2 will have user entity as host entity, or commerce line item will have commerce order as host entity.

$entity = entity_load('field_collection_item', $your_file_collection_id);
$host_entity = $entity->hostEntity();
echo $host_entity->nid;

I know this question is kind of old but I wanted to just give a quick answer because I had the same problem and stumbled upon here and the existing answers didn't satisfy me (though I'm not saying they don't work, I just found a simpler way to solve my problem). I just hope it may help anyone else finding this thread.

Anyway my solution is to just use the hostEntity() method of the field-collection entity. Simple example:

$var = $content["field_image_title"]["#object"];
$parent_node = $var->hostEntity();
$nid = $parent_node->nid; // for the node id, similarily for other values of the node.

Tags:

Entities