Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

JavaScript On Page

Go to End

6 Posts   1968 Views


Community Member, 24 Posts

23 August 2011 at 5:32am

Edited: 23/08/2011 5:33am

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=";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;;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.


Community Member, 60 Posts

23 August 2011 at 8:30am

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() {



Community Member, 24 Posts

23 August 2011 at 8:51am

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.


Forum Moderator, 5523 Posts

23 August 2011 at 8:01pm

@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 -


Community Member, 24 Posts

23 August 2011 at 11:20pm

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.


Community Member, 3 Posts

4 February 2015 at 11:40pm

<script async src="//"></script>
<!-- Dinowap -->
<ins class="adsbygoogle"
(adsbygoogle = window.adsbygoogle || []).push({});

this is my google adsence how to put into silverstripe site plshelp me pls tel me simple thanks in advance..........