Skip to main content
  • Guides & Documentation

Knowledgebase

Featured articles, how-to guides and quick tips.

Get Media Video URL in Twig - Drupal 8

Sometimes it may be useful to access the raw media file URL/URI value for a video file that has been uploaded via a Media field on an entity type.

In your Twig template, you may wish to display the raw URL of the file, rather than the embedded video or rendered entity as Drupal 8 natively provides.

It's really simple to access the raw URI. Simply use the following syntax in your Twig file (which will work for nodes, custom block templates, and paragraphs):

{{ file_url(content.field_video[0]['#media'].field_media_video_file.entity.uri.value) }}

Don't forget to replace the bolded text above with the machine name of your Media video field.