I am trying to get the field ID of of a field collection item being rendered in a field collection theme twig file: field-collection-item--field-name.html.twig.

I am able to render content using {{content.field_name}} but I need a unique identifier to create an anchor link. I can see an id is available using kint(item) but cant seem to figure out the proper syntax.

Any help would be greatly appreciated...

1 Answer 1


You can get The field collection item ID in field-collection-item.html.twig

{{ item['#field_collection_item'].id() }}

or you can get it from field-collection-item--field-name.html.twig, or other field template of field collection item.

{{ element['#items'].getEntity().id() }}

You can find these functions under Available Methods Tab when you printing out variables from twig template. You can use public methods.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.