Forum

Thread tagged as: Field-Types

Using fieldtype "Youtube" together with "fancybox" (lightbox)

Hi,

I am trying to use the YouTube-fieldtype together with fancybox-js. I want to show the thumbnail-image, when clicked, get the video in a lightbox, like this: https://fancyapps.com/fancybox/ (look for the link: "Youtube (iframe)").

I'm almost there, but I need to get a URL with this syntax "https://www.youtube.com/embed/L9szn1QQfas?autoplay=1" from the fieldtype).

So I hoped the fieldtype had an output called "ID", that would just give me "L9szn1QQfas". But I can only see "url" and "embed" as possible outputs. https://docs.grabaperch.com/addons/field-types/youtube/

Has this been requested before?

The page I am working on is this: https://comeshine.granqvist.no/videos (work in progress)

Svein Are Gronsund

Svein Are Gronsund 0 points

  • 5 years ago

Hi,

You could do this without the youtube fieldtype, and just have the user enter the video ID rather than the whole URL. So something like:

<a href="https://www.youtube.com/embed/<perch:input type="text" id="vidid" required="true" label="Video ID" />?autoplay=1">
    <img src="https://img.youtube.com/vi/<perch:input type="text" id="vidid" required="true" label="Video ID" />/0.jpg"
</a>

Not sure how the code needs to be structured for the lightbox but does this look ok? The /0.jpg links to the full size image for the video. There are other options you could use here, I can't remember them but I am pretty sure there is 1.jpg-4.jpg and a default.jpg at least

Hi, great info. I didn't know about the image-trick:

https://img.youtube.com/vi/{id}/0.jpg

But I kind of like getting all the meta-data to display together with the video, so I would really like to use the fieldtype.

Hmm in that case you might need to use PHP to use some find/replace to extract the ID from the URL.... though someone else may have a better idea!

I found out that I could fetch the ID by using "youtubeID" (undocumented):

https://www.youtube.com/embed/<perch:content id="video" type="youtube" output="youtubeID" />?autoplay=1
Drew McLellan

Drew McLellan 2638 points
Perch Support

That would be output="id" as well.