Jump to:

5539 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Tinymce: template button doesn't insert the content of my template

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

Page: 1
Go to End
Author Topic: 292 Views
  • jaaf
    Avatar
    Community Member
    24 Posts

    Tinymce: template button doesn't insert the content of my template Link to this post

    Hi,

    I am trying to customize the tinymce in the CMS in order to be able to enter small html templates that are of the following form:

    <div class="my-note">
       enter the text of your note here
    </div>


    without toggling to html edition.

    I put this in mysite/_config.php

    HtmlEditorConfig::get('cms')->enablePlugins('template');
    HtmlEditorConfig::get('cms')->addButtonsToLine(2, 'template');
    HtmlEditorConfig::get('cms')->setOptions(array('template_templates'=>array(
    array('title'=>'div-note','src'=>'mysite/templates/note.html','description'=>'Note'),
    array('title'=>'div-listing','src'=>'mysite/templates/listing.html','description'=>'Listing'),
    array('title'=>'div-code','src'=>'mysite/templates/code.html','description'=>'Code'),

    then I wrote the following templates in mysite/templates/

    note.html

    <div class="my-note"> enter the text of your note here
    </div>


    and similar for listing.html and code.html

    Then I visited mysiteadress/dev/build
    and mysiteadress/admin/?flush=all

    Results:
    I have a button in the editor toolbar that allow to open a window and to chose the template.
    But what is injected in my page is not the template but
    <p> enter the text of your note here</p>
    I don't understand why I have my text in paragraph instead of the div I put into the template?

    Thank you for help.

  • jaaf
    Avatar
    Community Member
    24 Posts

    Re: Tinymce: template button doesn't insert the content of my template Link to this post

    I eventually had it working

    I don't yet understand clearly but it has something to do with a line in my _config.php

    HtmlEditorConfig::get('cms')->setOption('valid_elements', '*

    • ');

    At the beginning I had this line added with a long list of accepted tags but without div. I tried to add div but it was still not working. Thus I changed the list with '*

    • ' and It worked.
      But what I don't understand is why when I completely remove the line it goes on working ?!

  • Sygmoral
    Avatar
    Community Member
    23 Posts

    Re: Tinymce: template button doesn't insert the content of my template Link to this post

    Important to note is that config changes do not take effect until you do a complete page load. AJAX loads don't refresh the config, no matter what you've changed in the code. So in normal use, since SS uses AJAX for all page loads, the config will never refresh after first logging in.

    I, at least, have found no way around this.

    It may explain that last concern you voiced, and perhaps also some others.

  • jaaf
    Avatar
    Community Member
    24 Posts

    Re: Tinymce: template button doesn't insert the content of my template Link to this post

    Thank you Sygmoral

    I have taken notice.

    292 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.