I am having hard time with getting the value of YouTube video thumbnail URL, in order to use it as background image in a template file.

I created a video content type and added a remote video field (field_url_vid2). The output format is thumbnail.

{{content.field_url_vid2}} gives the full HTML markup, but I just want the value of the src attribute.


To get the YouTube video thumbnail URL in twig!
Try with:

{{ file_url(content.field_url_vid2.0['#media'].thumbnail.0.entity.uri.value) }}
  • Hi I just got a "/" as result. I am inserting this in node--video.html.twig – yazzou Nov 25 '20 at 8:42
  • In kint content.field_url_vid2.0['#media'].thumbnail.0.entity.uri.value NULL – yazzou Nov 25 '20 at 9:03
  • use twig_vardumper module and do {{ dump(content.field_url_vid2.0['#media']) }} see if exist and then {{ dump(content.field_url_vid2.0['#media'].thumbnail.0.entity) }} i have tested this it works for me – berramou Nov 25 '20 at 11:30
  • Unfortunately it does not even appear in the tree...maybe it is related to the preprocess functions introduced in theme ? I did not do it myself. So i need to investigate more – yazzou Nov 25 '20 at 18:20
  • Maybe, do you use a custom theme ? i have tested it with default theme and bootstarp theme it works, and i used the remote video with it's default config, take a look if your thumbnail disabled in the manage display or something – berramou Nov 26 '20 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.