Get video thumbnail URI in twig theme template

Created on 7 November 2017, over 7 years ago
Updated 16 December 2022, over 2 years ago

I'm trying to get the youtube thumbnail URI in Drupal 8 twig view template so that I can use it as a CSS background for a div element rather than directly on the page in an img tag.

I see that I can find the URI using a preprocess function, but I can not figure out how to get the URI into the view template. Then for it to only apply to the specific content type I'm using.

themename.theme:


function THEMENAME_preprocess_image(&$variables) {
	$variables['uri']
}

I was able to get it working by using '{{ fields.field_youtube.content }}' in the view template then setting the 'image.html.twig' template to only return '{{ attributes.src }}', however, this would target all images that happen to be using the global 'image.html.twig' template.

Is there a more appropriate way to get the youtube thumbnail URI into a twig view template?

Thank you.

πŸ’¬ Support request
Status

Active

Version

1.5

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024