6

I want to make it super easy for my user to embed a video from YouTube (maybe eventually from other sources) without having to get the iframe code. They should only have to enter the URL for the video, and maybe check a couple of optional settings, and the code will do the rest.

I'm planning to share the snippet and field architecture I develop here to save myself/others time in the future, but if someone else has already done this and wants to share first, even better!

6

From basic to robust:

Redactor has a plugin along that same vein but it's more basic—feed it a URL and it spits out the embed code in a Redactor field.

Craft-video-embed-utilty sounds like it might work as a basic option here. It's not a field type but a Twig filter that'll take the video URL the user enters (you could use it with any field, including a plain text field) and then spit out the necessary Twig embed code. If you want to build your own "options" from scratch, this could work.

Embedded Assets allows you to use embeddable media such as YouTube videos to your assets manager and spit out the embed code necessary.

Dukt's premium Videos plugin is probably the most robust option. It'll actually connect to YouTube or Vimeo, hooks into Craft's interface, and visually allow you to search for and embed videos. It includes a videos field type that matrix compatible.

|improve this answer|||||
  • Great options. I think I'll try Embedded Assets unless it ends up slowing anything down. Thanks! – Katie Fritz Sep 14 '16 at 15:15
4

There are quite a few plugins here that you can use.

Some Video Plugins on Straightup Craft

My personal preference after trying some of these out is

Embedded Assets

|improve this answer|||||
  • 1
    +1, didn't know about Embedded Assets, that looks nice. – RitterKnight Sep 12 '16 at 20:55
  • 1
    It's really nice. I used to create video "channels" but now I just create a video asset source and seems more user friendly. – AbbeyDesign Sep 12 '16 at 21:00
  • Embedded assets looks perfect! Thanks a bunch. – Katie Fritz Sep 14 '16 at 15:14
2

I've always had a Plain Text field for the user to paste a Vimeo or YouTube URL into and then used the Embedder plugin in the template to generate the correct embed code (with options to turn off related videos etc).

{% set video = craft.embedder.url(matrix.videoUrl, {max_width:1200, youtube_rel:0, youtube_showinfo:0, vimeo_portrait:'false', vimeo_title:'false', vimeo_byline:'false'}) %}
<div class="widescreen">{{ video.embed_code }}</div>
|improve this answer|||||
  • 1
    I'm gonna say usually a plugin is a bit sexier and user friendly. Using a text field is not going to show a preview of the video or let the user know they've entered a valid url or not. – AbbeyDesign Sep 14 '16 at 17:07
2

I try to avoid too many plugin dependencies and user exposure to embed code.

For those reasons my setup has just one input field for YouTube videos, "YouTube ID", which is the video's ID users copy and paste after they've found the video they're after on YouTube.

This is part of a Matrix field that allows users to insert all kinds of components (text, quotes, videos etc.).

It'll take you only a few minutes to set up in the fields, not much code for the Matrix, and gives you a DRY component for videos.

|improve this answer|||||

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.