21310 Posts in 5739 Topics by 2604 members
|Go to End|
3 February 2009 at 10:12am
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.
PS. By the looks of it silverstripe seems like a CMS I will use a lot if I get back into developing.
4 February 2009 at 2:14am Last edited: 4 February 2009 2:14am
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">
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.
4 February 2009 at 3:01am
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 & 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 & 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.
|Go to Top|