Page 1 of 1

Embedding Youtube video

Posted: Wed Mar 23, 2016 6:05 pm
by SimonF
Hello folks,

Have been trying to embed a Youtube video. Whilst copying the Embed URL produced by Youtube works fine, with the iFrame tags, it's not resizeable for a fluid site.

I've been trying to read up on how to do it & have tried this from the CMS Documentation using the Embed tag.

http://docs.cmsmadesimple.org/tags/cmsms-tags/embed

This is the error I now get:

Code: Select all

Syntax error in template "content:content_en"  on line 14 "
{embed url="https://www.youtube.com/watch?v=3qOOocqfkZs"}

" unknown tag "embed"
The embed code from Youtube is this:

Code: Select all

<__iframe width="854" height="480" src="https://www.youtube.com/embed/3qOOocqfkZs" frameborder="0" allowfullscreen></__iframe>
This is the tag I now have in my Content page:

Code: Select all

{embed url="https://www.youtube.com/watch?v=3qOOocqfkZs"}
I've added {embed header=true} to the Simplex Template and the

Code: Select all

#myframe {
height: 600px;
}
to both the Simplex Core and Layout stylesheets.

Can anyone please tell me what I'm doing wrong?

Regards,

Simon

Re: Embedding Youtube video

Posted: Wed Mar 23, 2016 8:02 pm
by Rolf
Create a UDT named "youtube" with the content:

Code: Select all

$id = isset($params['id']) ? $params['id'] : '';

if ( $id != '' )
{
  echo '<div class="video">';
  echo '<__iframe width="560" height="315" src="//www.youtube.com/embed/' . $id . '?rel=0&showinfo=0" frameborder="0" allowfullscreen></__iframe>';
  echo '</div>';
}
NOTE: remove the __ in the iframe tags in the code --^

In your page or article:

Code: Select all

{youtube id='3qOOocqfkZs'}

Re: Embedding Youtube video

Posted: Wed Mar 23, 2016 8:13 pm
by scooper
Looks like the old embed tag isn't in the new 2.0 version of CMSMS which is why you're getting the error.

I use a very similar User Defined Tag to the one Rolf suggested. It's something I often use so I keep it handy as a gist:

https://gist.github.com/millipedia/10017099

That also includes some CSS classes that you can use to allow it to be resized and keep the aspect ratio when you embed it in a responsive site.

s.

Re: Embedding Youtube video

Posted: Thu Mar 31, 2016 1:27 pm
by master3395
2.0 has the new content embedding included.

Re: Embedding Youtube video

Posted: Thu Mar 31, 2016 4:26 pm
by SimonF
So how's it done then, master3395?

The method in the 2.0 Documentation is as I listed above & doesn't work.

Thanks to Scooper & Rolf I have it working after a fashion. The vids still don't shrink below a certain resolution, meaning mobile phone users get left-right scrolling, though I fear this is a Youtube limitation.

Re: Embedding Youtube video

Posted: Thu Mar 31, 2016 6:22 pm
by Jeff
I don't use a plugin, I simply copy the code from youtube and paste it in my template.

To get a responsive video you need to setup CSS properly. I did it a while back a quick search on google gave me https://css-tricks.com/NetMag/FluidWidt ... hVideo.php I don't know if this is the one I used or not.

Re: Embedding Youtube video

Posted: Thu Mar 31, 2016 6:49 pm
by SimonF
Have the last 2 posters actually read my original post???

Re: Embedding Youtube video

Posted: Thu Mar 31, 2016 7:00 pm
by Jeff
Yes, I did and I address both points in my reply.