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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

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

PageClass in HTMLEditor

Go to End

4 Posts   781 Views


Community Member, 46 Posts

22 January 2014 at 7:51am

Edited: 22/01/2014 7:54am

Some of the pages in my Silverstripe 3.1 website have specific styles, so I used the page class to target just those pages. Now the issue is that I am not able to make that distinction in the CMS because it does not include the pageclass.

I found HtmlEditorConfig::get('cms')->setOption('body_class', page_class); which sounded very promising, but that is a static setting: it is set once upon the first page load within the CMS. Any next page loaded via ajax will use those same editor settings, even if the page is of a different type. So what I really need is something like this, but refreshing every time the HTMLEditor is displayed.

One way is making the CMS reload upon every page load (i.e. disable the ajax for CMS page loads), but I'm not sure whether that's possible.

The other (and more prefered) way is making the HTMLEditor config settings come along with an ajax load. At the moment only Content is included in the json; it could easily include a ssTinyMceConfig field, in order to overwrite any current TinyMCE settings. Is there a specific reason this was not done, some kind of issue perhaps? It might just be because it was deemed unnecessary, so in that case I'd be interested to know how to make it happen of course.

A third way might be to hack into a single config field by adding <script>ssTinyMceConfig.body_class="..."</script> in the returned Content field, but I'm not sure how to do that either, and I'm not sure it would work.


Community Member, 46 Posts

12 February 2014 at 11:00am

Edited: 12/02/2014 11:00am

So am I correct in assuming it is currently impossible to have different styles in different PageTypes, within the CMS?

Framework › Reference › Typography for example mentions how different HTMLEditorFields can have different styles, but that doesn't actually work (anymore) does it? I don't see any class like "Content" being applied anywhere on TinyMCE.


Community Member, 187 Posts

15 February 2014 at 8:33am

Just in case anyone stumbles upon this thread, I've packaged up a small module that enables you to do this:


Community Member, 46 Posts

15 February 2014 at 9:58am

Edited: 15/02/2014 9:59am

That is awesome, thank you!

I've implemented it with a single line in Page.php (inside getCMSFields), which puts the correct class name using get_called_class (available since php 5.3):

$fields->dataFieldByName('Content')->setAttribute('data-mce-body-class', get_called_class());