Jump to:

22993 Posts in 11595 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » iframes and tinyMCE

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

Page: 1 2
Go to End
Author Topic: 3730 Views
  • Henry24
    Avatar
    Community Member
    9 Posts

    iframes and tinyMCE Link to this post

    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?

  • Chris Hope
    Avatar
    Community Member
    18 Posts

    Re: iframes and tinyMCE Link to this post

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

  • Chris Hope
    Avatar
    Community Member
    18 Posts

    Re: iframes and tinyMCE Link to this post

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

  • Anatol
    Avatar
    126 Posts

    Re: iframes and tinyMCE Link to this post

    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

  • Nobrainer Web
    Avatar
    Community Member
    134 Posts

    Re: iframes and tinyMCE Link to this post

    Thanks alot Chris,

    This solved my problems of embedding Youtube videos in the editor

  • mrsteveheyes
    Avatar
    Community Member
    15 Posts

    Re: iframes and tinyMCE Link to this post

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

  • mrsteveheyes
    Avatar
    Community Member
    15 Posts

    Re: iframes and tinyMCE Link to this post

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

    }

  • socks
    Avatar
    Community Member
    190 Posts

    Re: iframes and tinyMCE Link to this post

    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

    3730 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.