5415 Posts in 1651 Topics by 1188 members
|Go to End|
22 January 2014 at 7:51am Last edited: 22 January 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.
12 February 2014 at 11:00am Last edited: 12 February 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.
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:
15 February 2014 at 9:58am Last edited: 15 February 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):
|Go to Top|