0

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.

1 Answer 1

1

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

{{ file_url(content.field_url_vid2.0['#media'].thumbnail.0.entity.uri.value) }}
5
  • Hi I just got a "/" as result. I am inserting this in node--video.html.twig
    – yazzou
    Commented Nov 25, 2020 at 8:42
  • In kint content.field_url_vid2.0['#media'].thumbnail.0.entity.uri.value NULL
    – yazzou
    Commented Nov 25, 2020 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
    Commented Nov 25, 2020 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
    Commented Nov 25, 2020 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
    Commented Nov 26, 2020 at 9:30

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.