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.

Customising the CMS /

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

Tinymce: template button doesn't insert the content of my template


Go to End


4 Posts   1316 Views

Avatar
jaaf

Community Member, 24 Posts

13 February 2014 at 6:02am

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.

Avatar
jaaf

Community Member, 24 Posts

13 February 2014 at 8:16am

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 ?!

Avatar
Sygmoral

Community Member, 46 Posts

13 February 2014 at 1:36pm

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.

Avatar
jaaf

Community Member, 24 Posts

13 February 2014 at 8:53pm

Thank you Sygmoral

I have taken notice.