I have created a custom media bundle using the Media Entity module. Here is a screen grab of the media bundle:

enter image description here

I have created a Twig template media--image.twig.html

I am able to retrieve all of the field values via the content variable in Twig but I'm having difficulty retrieving the field_image URL.

Here is a snapshot of the output from {{ kint(content.field_image) }}:

enter image description here

How do I extract the URL? I can see a target Id, so presumably I can load the entity in the preprocess function and pass through the variable but I would've expected the full target object to be available within the Twig template?

1 Answer 1


Image URL Formatter

This module adds a url formatter for image field. Then you can output image url directly.

Enable the module, edit your image field, change the formatter to url.

Now {{ content.field_image }} will print the url instead of rendering the image.

  • Thanks, that works. The only additional task was to override the field--media--field-image--image.twig.html template to remove the divs from the Image URL Formatter output. May 17, 2016 at 9:12

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.