Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Update HTMLEditor config upon pageload #929

JorisDebonnet opened this Issue · 3 comments

3 participants

JorisDebonnet Loz Calver Simon Welsh

One way to style pages on a SilverStripe website differently depending on their PageType, is using the class it puts on the body tag. E.g., .HomePage > div:first-child could be styled differently from the default on .Page.

Unfortunately, it is currently impossible to use those css classes in the HTMLEditor.
HtmlEditorConfig::get('cms')->setOption('body_class', page_class); can be used to set the body's class in the editor, but only on a full page load: any subsequent ajax loads do not update that body class. Since SilverStripe loads everything with ajax now, it's impossible to have the correct styles inside the HTMLEditor for different PageTypes. This is also not very intuitive: one would expect the config options that are set during php execution to actually take effect.

There are several ways to fix this.

The most flexible one would be to not only send a Content field upon the ajax loads, but also a new ssTinyMceConfig.

Alternatively, a script tag in the Content field could set any overwritten config options, such as <script>ssTinyMceConfig.body_class="..."</script>. This way, no extra field needs to be added to the returned json, should that be a difficulty.

Loz Calver

Hi @JorisDebonnet,

I’ve been struggling with the same issue lately, and this issue reminded me about it, so I put together a small module to allow devs to add CSS classes using ->setAttribute('data-mce-body-class', 'HomePage');:

This doesn’t really resolve this issue, updating configs via AJAX could be potentially useful elsewhere, but it might be of some use to you. :)


That, sir, is awesome! Thanks for sharing.

For my own application, I needed to add only one line to my php files, in Page.php: $fields->dataFieldByName('Content')->setAttribute('data-mce-body-class',get_called_class());
(get_called_class() is available since php 5.3)

One other note: your project name is missing an l :)

Loz Calver

Heh, thanks for pointing that out :)

Simon Welsh simonwelsh added the 3.1 label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.