21493 Posts in 5784 Topics by 2622 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 497 Views |
-
JavaScript On Page

23 August 2011 at 5:32am Last edited: 23 August 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="http://player.ooyala.com/player.js?height=360&deepLinkEmbedCode=Y0NGRjMjplERX85mydGU70V1qVvFPvbX&video_pcode=oza2w6q8gX9WSkRx13bskffWIuyf&autoplay=1&embedCode=Y0NGRjMjplERX85mydGU70V1qVvFPvbX&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:
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.
-
Re: JavaScript On Page

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() {
parent::init();Requirements::javascript("js/someJavaScript.js");
}
} -
Re: JavaScript On Page

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 javascriptWe would really like a simple solution to simply embed any JS into the content of a page.
Thanks in advance.
-
Re: JavaScript On Page

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 - http://www.ssbits.com/tutorials/2010/2-4-using-short-codes-to-embed-a-youtube-video/
-
Re: JavaScript On Page

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.
| 497 Views | ||
|
Page:
1
|
Go to Top |



