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 forum.silverstripe.org 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

Allowing Scripts in the HTML Editor


Go to End


3 Posts   2510 Views

Avatar
lypa

Community Member, 1 Post

14 June 2011 at 5:12am

Hi All,

I'm extremely new to php and SS CMS!

I am having trouble getting some scripts to work (which I am transferring from my old html website).
I have searched the forum for solutions, and so far have found that I should edit mysite/config.php to include:

HtmlEditorConfig::get('cms')->setOption('extended_valid_elements',"script[type|src],img[class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|usemap],iframe[src|name|width|height|align|frameborder|marginwidth|marginheight|scrolling],object[width|height|data|type],param[name|value],map[class|name|id],area[shape|coords|href|target|alt]");

However, my script still won't work as the CMS seems to place comments bewteen scripts with <![CDATA[ as shown here:

<script type="text/javascript" src="http://www.db798.com/pictobrowser/swfobject.js">// <![CDATA[
<script type="text/javascript">[CDATA[<![CDATA[<![CDATA[<![CDATA[// <![CDATA[
var so = new SWFObject("http://www.db798.com/pictobrowserp.swf", "PictoBrowser", "940", "590", "8", "#3a3a3a"); so.addVariable("source", "album"); so.addVariable("userName", "user"); so.addVariable("names", "101125"); so.addVariable("albumId", "0000000123"); so.addVariable("titles", "off"); so.addVariable("displayNotes", "off"); so.addVariable("thumbAutoHide", "off"); so.addVariable("imageSize", "original"); so.addVariable("vAlign", "mid"); so.addVariable("vertOffset", "0"); so.addVariable("colorHexVar", "3a3a3a"); so.addVariable("initialScale", "off"); so.addVariable("bgAlpha", "5"); so.write("PictoBrowser110419211155");
// ]]]]]]]]<![CDATA[><![CDATA[><![CDATA[><![CDATA[>]]]]]]<![CDATA[><![CDATA[><![CDATA[>]]]]<![CDATA[><![CDATA[>]]]][CDATA[
// --&gt;]]></script>

Does anybody have any ideas????

Many thanks!!!

Avatar
Ironcheese

Community Member, 36 Posts

27 January 2012 at 4:43am

Edited: 27/01/2012 4:44am

I know this is a old post, but i just had the same problem and found a (rather) hacky solution:

Add this to your Page.php inside the Page Class.

public function onBeforeWrite(){
		parent::onBeforeWrite();
		
		if(!empty($this->RawContext)){
			$searchFor = array(
				'<![CDATA[',
				']]]]>>]]>',
				']]>'
			);
			
			$this->RawContext = str_replace($searchFor, '', $this->RawContext);
		}
		
	}

My field is "RawContext" where i used some javascript.

You should "clean" all the CDATA Tags from the field first. Then the onBeforeWrite will filter those new added tags out.

cheers

Avatar
Loopy

Community Member, 20 Posts

1 February 2012 at 3:29am

Edited: 01/02/2012 3:33am

I have had similar problem with <script type="text/javascript" src+"url" statement

Did you add this to the Page.php file at mysite/code/Page.php?

Also re RawContext, what is this?

Any help gratefully received. I have tried a number of suggestions on the forum but so far none have worked. I need to be able to find a way to use <script type="text/javascript" src+"url" statement.

If I can't do this then I will have to look at an alternative cms which would be a shame because in every other regard Silverstripe seem to be just what I need.