1

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

2

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.

1
  • 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. Commented May 17, 2016 at 9:12

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.