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 to another node that has the stock_photo_search
field, 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?
getImageUrl()
), you can use{{ node.field_stock_photo.0.imageurl }}
.{{ node.reference.0.entity.field_stock_photo.0.imageurl }}
. The build array of a nested entity doesn't exist yet when the parent is rendered, so this is too early to access the output of the field formatter in{{ content }}
.view()
in PHP though, to build the render array earlier. See the answer.