Jump to:

23355 Posts in 17873 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Embed Video from Youtube

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2983 Views
  • reekrd
    Avatar
    Community Member
    9 Posts

    Embed Video from Youtube Link to this post

    Hi I'm new to SilverStripe and I haven't kept my coding up to date so I'm pretty damn rusty. Anyhow. I want to show an embedded video from youtube on my home page. Having looked through the first two tutorials I figured I could add a new HTMLVarchar DBField to my HomePage and then simply copy paste the embed snippet from youtube.

    That didn't work. Firefox says: XML Parsing Error: not well-formed and Safari says something about an EntityRef. As most of you already know this is due to the & in the embed code. And replacing & with & solves the problem.

    However, manually replacing & with & isn't an option. So I thought maybe I could use PHP and simply replace & with & but after digging around for a while I learnt that you can't pass variables to the controller functions. So now I'm stuck. And would appreciate any help on where to begin. Can I get to the data before it is loaded into the DataObjects and place the PHP function there or what would be the correct way of doing this seemingly simple operation.

    Best
    .rickard

    PS. By the looks of it silverstripe seems like a CMS I will use a lot if I get back into developing.

  • MrHyde
    Avatar
    Community Member
    23 Posts

    Re: Embed Video from Youtube Link to this post

    Hi reekrd,

    i just took a look on the documentations.
    "Class HTMLVarchar represents a variable-length string of up to 255 characters"

    The youtube enbedd-code should contain more than 255 charcters, so i guess this should not work for you. This is typical youtube enbedd.code:

    <object width="425" height="344">
       <param name="movie" value="http://www.youtube.com/v/F8mZGDFDceU&hl=de&fs=1"></param>
       <param name="allowFullScreen" value="true"></param>
       <param name="allowscriptaccess" value="always"></param>
       <embed src="http://www.youtube.com/v/F8mZGDFDceU&hl=de&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344">
    </embed>
    </object>

    What i would try to do is just to store the video-url into a database-field.
    Then you should create an youtube.ss file into your themes/mytheme/templates/includes folder. Just copy the complete embedd-code into this file and replace src="http://www.youtube.com/v/F8mZGDFDceU&hl=de&fs=1" with src="$yourURLvar". Finaly you should be able to include this youtube.ss file into HomePage.ss by

    <% include youtube %>

    .
    Just some idea, i dont know if this will work. But thats the way i would try to do it.
       

  • reekrd
    Avatar
    Community Member
    9 Posts

    Re: Embed Video from Youtube Link to this post

    Hi MrHyde,

    I was actually using HTMLText and not HTMLVarchar in the database. So the embed code is all there. The error I get is related to the & in the address part of the embed code. If & sign are not escaped &amp; you will get an error. If you just put an & sign in any of your .ss files you will get the same error. Make that into an HTML Entity &amp; and you wont get an error.

    Showing someone how to copy and paste the embed code from youtube and into this field in the CMS isn't to hard. But having to have them manually change things in the embed code is, in this case, to much to ask for. Also they would lose the ability to customize the embedded player.

    Cheers
    .rickard

    2983 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.