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


Go to End
Reply

13 Posts   4311 Views

Avatar
Henry24

4 April 2011 at 2:07pm (Last edited: 4 April 2011 2:08pm), Community Member, 9 Posts

Hi,

I've searched up and down all over this site and google and have seen a bunch of people with the same issue but no answer still (or answers that don't work).

When you put in an iframe (like google maps), SS will turn the <iframe></iframe> into a <iframe /> tag and it will break the layout.

I know this is SS doing it because looking back at tinyMCE shows the tags as <iframe></iframe>

I read in another post that a solution is to put a space between the tags, so it becomes <iframe> </iframe>, however, if you do that from the HTML editor in tinyMCE, it will strip out the blank space (and anything else you put between the iframe tags) putting me back in the same situation.

ive tried using these 3 settings in mysite/_config.php file but it doesn't fix it

HtmlEditorConfig::get('cms')->setOption('verify_html', 'false');
HtmlEditorConfig::get('cms')->setOption('element_format', 'html');
HtmlEditorConfig::get('cms')->setOption('cleanup', 'false');

I can understand that the editors are trying to be as xhtml compliant as possible but we live in an IE do-your-own-thing dominated world so that's not good enough for now. Is there solution to this?

Avatar
Chris Hope

7 May 2011 at 10:16pm Community Member, 18 Posts

You need to do something along the lines of this on the server-side, although I haven't had issues with the space being stripped out on the client side myself. Even if it doesn't strip it client side, doing this server-side is a good idea anyway in case you forget, or it's someone else editing content that doesn't know about it.

function onBeforeWrite() {
$this->Content = str_replace("></iframe>", "> </iframe>", $this->Content);
parent::onBeforeWrite();
}

Avatar
Chris Hope

9 May 2011 at 11:20am Community Member, 18 Posts

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();
}

Avatar
Anatol

25 June 2011 at 8:43pm 126 Posts

Thanks a lot! Silverstripe used to move all html content after an iframe between the opening and closing iframe tags, so everything after an iframe would disappear. Your code fixes that issue.

Cheers!
Anatol

Avatar
Nobrainer Web

5 July 2011 at 9:36pm Community Member, 135 Posts

Thanks alot Chris,

This solved my problems of embedding Youtube videos in the editor :-)

Avatar
mrsteveheyes

13 July 2011 at 10:57pm Community Member, 15 Posts

This looks like it will be really helpful. But where do you put the onBeforeWrite() function? in mysite/_config.php?

Avatar
mrsteveheyes

13 July 2011 at 11:04pm Community Member, 15 Posts

Oh, fixed it. I added it to my Page class in mysite/code/Page.php. See bellow:

<?php
class Page extends SiteTree {

   static $icon = "themes/default/images/icons/page";

   public static $db = array(
   );

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

}

Avatar
socks

12 November 2011 at 12:34pm Community Member, 190 Posts

Any way to keep a class from being stripped as well? I'd like to allow the user to apply Left, LeftAlone, Center classes from the style drop down.

I hope that SS3 fixes these issues. It should be easy to add video to content.

Thanks

Go to Top