Get node ID that field belongs, in field.tpl.php being displayed in a block on any page I have a 'Gallery' content type that has an entity reference field, which I use to reference other nodes of the 'Gallery Item' content type. When creating a 'Gallery' I use the nodeblock module to automatically create a block with this content.

So when I place this block in any page, let's say the homepage, I have it displaying the 'Gallery' title and a body on top, and below that, each 'gallery item' using the 'rendered entity' field formatter.

What I also need, is to somehow display the node id of each 'gallery item'.

I've tried editing the entity reference field template by creating a custom field.tpl.php template for it, but I can't find a way of accessing the node ID of each corresponding item.

Please help!
Found my solution!
I was trying to access the node id from the field.tpl.php template because I wanted to add a CSS ID (using the node id) to the field outer wrapper (a div). Which was in this field template.

What I ended up doing was removing this div wrapper from the field template, and just adding the CSS id to the div wrapper in the node.tpl.php template.

Since I only needed this CSS id in certain a view mode, I created a node template for my specific view mode.