Jump to:

23490 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » JavaScript On Page

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: 812 Views
  • davede
    Community Member
    24 Posts

    JavaScript On Page Link to this post

    Hi all,

    Been looking around the forums for a solution but keep hitting dead ends and threads that aren't very clear.

    I'd like to embed the following code on our site:

    <script src="http://player.ooyala.com/player.js?height=360&amp;deepLinkEmbedCode=Y0NGRjMjplERX85mydGU70V1qVvFPvbX&amp;video_pcode=oza2w6q8gX9WSkRx13bskffWIuyf&amp;autoplay=1&amp;embedCode=Y0NGRjMjplERX85mydGU70V1qVvFPvbX&amp;width=640"/>

    It is an embed code for a video that seems to use javascript instead of an iframe.

    I created a separate TextareaField for the CMS and made it the data type HTMLText. Then I put the place holder in the template.

    However when I publish the page all the script code gets escaped like so:

    &lt;script src=&quot;http://player.ooyala.com/player.js?height=360&amp;amp;deepLinkEmbedCode=Y0NGRjMjplERX85mydGU70V1qVvFPvbX&amp;amp;video_pcode=oza2w6q8gX9WSkRx13bskffWIuyf&amp;amp;autoplay=1&amp;amp;embedCode=Y0NGRjMjplERX85mydGU70V1qVvFPvbX&amp;amp;width=640&quot;/&gt;

    How can we embed the code on the page?

    Please note creating a separate page type every time we'd like to embed a video is not feasible.

    Any help would be much appreciated.

  • MagicUK
    Community Member
    60 Posts

    Re: JavaScript On Page Link to this post

    To load javascript into a page you have to add the requirement into the controller for the page you want it to be on:

    class Page_Controller extends ContentController {

       public static $allowed_actions = array (

       public function init() {


  • davede
    Community Member
    24 Posts

    Re: JavaScript On Page Link to this post

    Hi Magic UK,

    Thanks for the reply

    Perhaps I should have been a bit clearer.

    This is something that we need to do on a recurring basis.

    We'd like to embed videos in content.

    However the same issue extends to:
    - Google adsense code
    - Google widgets
    - any other embed code that uses javascript

    We would really like a simple solution to simply embed any JS into the content of a page.

    Thanks in advance.

  • Willr
    Forum Moderator
    5508 Posts

    Re: JavaScript On Page Link to this post

    @davede - in your example you would need to use $FieldName.RAW to stop any escaping. This does pose a slight security issue if you allow outsiders into your CMS which is usually very rare.

    Another popular method is using shortcodes - http://www.ssbits.com/tutorials/2010/2-4-using-short-codes-to-embed-a-youtube-video/

  • davede
    Community Member
    24 Posts

    Re: JavaScript On Page Link to this post

    Hi Will,

    You're a good man thanks for all the help.

    We changed the datatype to Text and put the RAW method on the end of the placeholder.

    That seems to work fine and now we can put whatever code we want into the page.

    I wasn't familiar with short codes thanks for the info. We may implement it in the future however for now we may just stick to the quick and dirty paste any code you want way.

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.