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.

General Questions

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

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

iframes and tinyMCE


Reply

13 Posts   4297 Views

Avatar
Chris Hope

12 November 2011 at 7:20pm Community Member, 18 Posts

An alternative is to use shortcodes, something I learned about after contributing this this thread.

There's a tutorial over at SS Bits which covers YouTube as an example here: http://www.ssbits.com/tutorials/2010/2-4-using-short-codes-to-embed-a-youtube-video/

Avatar
Lemonie

16 June 2012 at 12:38am Community Member, 70 Posts

I have followed the instructions but cannot get this to work. I have added the code to Page.php as below

<?php

class Page extends SiteTree {
   
   public static $db = array(

   );
   
   public static $has_one = array(

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

   //Remove Reports/todo tabs
   $fields->removeByName("To-do");
   $fields->removeByName("Reports");

      return $fields;
   }   
}

but I just get an error when I do a dev/build?

Can anybody help?

Avatar
Chris Hope

16 June 2012 at 7:48am Community Member, 18 Posts

It would help if you posted the error.

Avatar
petermeilahn

8 August 2013 at 2:32am Community Member, 1 Post

Hi, I have having the same issue for trying to put a soundcloud player on my site.

Thanks everyone and Chris Hope especially for posting the below.

I can change code in the files but would really appreciate a step by step instruction on how to do this ( I do clinical counseling and dabble in free human computer education and therapy interfaces for the public but can really only do programming "labor" - trying to be a full programmer makes my head hurt sometimes):

From Chris Hope:

Re: iframes and tinyMCE Link to this post
9 May 2011 at 11:20am

Now that I've actually tried this it doesn't work as expected because the content has already been loaded into the object using domdocument so it's already collapsed the iframe. I've used this regexp instead:

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

___________________

Thanks, Peter Meilahn - www.mindvolume.com

Avatar
socks

10 August 2013 at 12:44pm Community Member, 190 Posts

@petermeilahn

Add that code here: mysite > code > Page.php

<?php

class Page extends SiteTree {
   
   // Keeps TinyMCE from messing up iframe code
   function onBeforeWrite() {
      $this->Content = preg_replace('|<iframe(.*)/>|Uims', '<iframe\\1> </iframe>', $this->Content);
      parent::onBeforeWrite();
   }

}

class Page_Controller extends ContentController {

...

}