Created
December 17, 2020 20:24
-
-
Save bfodeke/7090e12425f04e104af1034366731138 to your computer and use it in GitHub Desktop.
D8/Twig: Get URL of embedded media entity reference
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://createdbycocoon.com/knowledge/get-media-video-url-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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment