Silverstripe Embedded iframe Fix
Posted by on 25 September 2012 03:24 PM

Sometimes you need to be able to embed an iframe using the TinyMCE editor in Silverstripe, for example if you are trying to insert a Google Map or a YouTube video.  By default, the editor mangles the HTML if there are iframe tags in the HTML - everything else on the page gets put into the iframe tags, and it does substitutions for '<' and '>', so they become '&lt;' and '&gt;'.  This completely destroys the content you are working on, forcing you to roll back to a previous revision of the page.  To avoid this, insert the following code into your Page class:

public function onBeforeWrite() { 
   $this->Content = preg_replace('|<iframe(.*)/>|Uims', '<iframe\\1> </iframe>', $this->Content); 

This solution was originally found on the SilverStripe forums.

Original source:

(1 vote(s))
Not helpful

Comments (0)
Post a new comment
Full Name:
CAPTCHA Verification 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).