Skip to main content
2 of 3
Highlighted code
leymannx
  • 18.8k
  • 6
  • 72
  • 126

How to get rendered content properties from an entity reference in Twig

I'm using the Stock Photo Search module, for particular image fields, and it has its own field type with interesting properties.

As far as I can tell, the only way to access the URI of the image is content.field_stock_photo[0]['#uri']. There is no node.field_stock_photo.0.entity.uri.value or similar. The only way to access the URI is through the rendered entity.

The problem I'm running into is when using a reference, I have no way to access this rendered entity from a reference. node.reference.0.entity.field_stock_photo.value doesn't do it, and as far as I can tell node.reference.0.content.field_stock_photo doesn't work.

How do I go about getting properties from a rendered entity of a reference in Twig?

Matt
  • 373
  • 1
  • 14