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

iframes and tinyMCE


Go to End


13 Posts   9203 Views

Avatar
Henry24

Community Member, 9 Posts

4 April 2011 at 2:07pm

Edited: 04/04/2011 2:08pm

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

Community Member, 18 Posts

7 May 2011 at 10:16pm

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

Community Member, 18 Posts

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

Avatar
Anatol

126 Posts

25 June 2011 at 8:43pm

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

Community Member, 138 Posts

5 July 2011 at 9:36pm

Thanks alot Chris,

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

Avatar
mrsteveheyes

Community Member, 15 Posts

13 July 2011 at 10:57pm

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

Avatar
mrsteveheyes

Community Member, 15 Posts

13 July 2011 at 11:04pm

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

Community Member, 191 Posts

12 November 2011 at 12:34pm

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