Jump to:

23377 Posts in 18296 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » Allowing Scripts in the HTML Editor

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
Go to End
Author Topic: 1171 Views
  • lypa
    Avatar
    Community Member
    1 Post

    Allowing Scripts in the HTML Editor Link to this post

    Hi All,

    I'm extremely new to php and SS CMS!

    I am having trouble getting some scripts to work (which I am transferring from my old html website).
    I have searched the forum for solutions, and so far have found that I should edit mysite/config.php to include:

    HtmlEditorConfig::get('cms')->setOption('extended_valid_elements',"script[type|src],img[class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|usemap],iframe[src|name|width|height|align|frameborder|marginwidth|marginheight|scrolling],object[width|height|data|type],param[name|value],map[class|name|id],area[shape|coords|href|target|alt]");

    However, my script still won't work as the CMS seems to place comments bewteen scripts with <![CDATA[ as shown here:

    <script type="text/javascript" src="http://www.db798.com/pictobrowser/swfobject.js">// <![CDATA[
    <script type="text/javascript">[CDATA[<![CDATA[<![CDATA[<![CDATA[// <![CDATA[
    var so = new SWFObject("http://www.db798.com/pictobrowserp.swf", "PictoBrowser", "940", "590", "8", "#3a3a3a"); so.addVariable("source", "album"); so.addVariable("userName", "user"); so.addVariable("names", "101125"); so.addVariable("albumId", "0000000123"); so.addVariable("titles", "off"); so.addVariable("displayNotes", "off"); so.addVariable("thumbAutoHide", "off"); so.addVariable("imageSize", "original"); so.addVariable("vAlign", "mid"); so.addVariable("vertOffset", "0"); so.addVariable("colorHexVar", "3a3a3a"); so.addVariable("initialScale", "off"); so.addVariable("bgAlpha", "5"); so.write("PictoBrowser110419211155");
    // ]]]]]]]]<![CDATA[><![CDATA[><![CDATA[><![CDATA[>]]]]]]<![CDATA[><![CDATA[><![CDATA[>]]]]<![CDATA[><![CDATA[>]]]][CDATA[
    // --&gt;]]></script>

    Does anybody have any ideas????

    Many thanks!!!

  • Ironcheese
    Avatar
    Community Member
    33 Posts

    Re: Allowing Scripts in the HTML Editor Link to this post

    I know this is a old post, but i just had the same problem and found a (rather) hacky solution:

    Add this to your Page.php inside the Page Class.

    public function onBeforeWrite(){
          parent::onBeforeWrite();
          
          if(!empty($this->RawContext)){
             $searchFor = array(
                '<![CDATA[',
                ']]]]>>]]>',
                ']]>'
             );
             
             $this->RawContext = str_replace($searchFor, '', $this->RawContext);
          }
          
       }

    My field is "RawContext" where i used some javascript.

    You should "clean" all the CDATA Tags from the field first. Then the onBeforeWrite will filter those new added tags out.

    cheers

  • Loopy
    Avatar
    Community Member
    20 Posts

    Re: Allowing Scripts in the HTML Editor Link to this post

    I have had similar problem with <script type="text/javascript" src+"url" statement

    Did you add this to the Page.php file at mysite/code/Page.php?

    Also re RawContext, what is this?

    Any help gratefully received. I have tried a number of suggestions on the forum but so far none have worked. I need to be able to find a way to use <script type="text/javascript" src+"url" statement.

    If I can't do this then I will have to look at an alternative cms which would be a shame because in every other regard Silverstripe seem to be just what I need.

    1171 Views
Page: 1
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.