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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

SyntaxHighlighter an Javascript in the CMS

Go to End

3 Posts   1005 Views


Community Member, 17 Posts

18 January 2012 at 2:45pm

Edited: 18/01/2012 2:46pm

I have SyntaxHighlighter working in the CMS (using the SyntaxHL plugin for TinyMCS). It's all fine and dandy and code shows perfectly on the front end.

The problem is Javascript. TinyMCE reformats all of my Javascript, adding multiple CDATA's to the point where the code is invalid (the problem is well documented in the forums, for example here).

But I have seen other SilverStripe sites that display Javascript on the front end without problem, such as the SilverStripe documentation.

Is there something I am missing? How can I display Javascript in formatted code blocks on the front end using SyntaxHighlighter. Bonus points for anyone that can get me to run executable JS that has been inserted into TinyMCE in the backend (I realize the security risks, just looking for proof of concept).

BTW, I have tried to modify 'valid_elements' in _config.php with no success; javascript is still rewritten to include CDATAs.

Thanks to all!


Forum Moderator, 1391 Posts

20 January 2012 at 6:07am

Edited: 20/01/2012 6:07am


I use the SyntaxHighlighter and the plugin on my site, and so far I haven't had any of the problems you describe. What it generates is something like this:

<pre class="brush: jscript;fontsize: 100; first-line: 1; ">
&lt;script type="JavaScript"&gt;

This is SilverStripe 246. It's definitely the <pre tag that prevents tinyMCE from messing with it - if I add it to HTML plain, without <pre, all javascript gets stripped away in my case... You do have the 'pencil' button installed and otherwise working in your editor, I presume?


Community Member, 17 Posts

25 January 2012 at 8:50am

Thanks for the reply martimiz.

I've got it working, I was using the wrong brush. I was mixing HTML and JavaScript (and SS template code), so I should have used the XML/HTML brush instead:

<pre class="brush: xml;fontsize: 100; first-line: 1; ">
&lt;% control Store %&gt;

		{$City}, {$State} {$Zip}

	&lt;script type="text/javascript"&gt;
		var MapJSON = jQuery.parseJSON('{$Top.StoreGeolocationJSON}');
	&lt;div id="map_canvas" style="width:500px;height:300px;"&gt;&lt;/div&gt;

&lt;% end_control %&gt;

Thanks again!