SMSGavin
SMSGavin

Reputation: 80

Kentico CKEditor Configure Style Set Dynamically

I'm using Kentico 9 and I'd like to be able to use different CK Editor style sets on different pages. I have added a style set to the styles.js file as follows.

CKEDITOR.stylesSet.add("mystyles", [{ name: "testone", element: "p" }]);

Then in the page I've added some JS as per the CK Editor web site.

if (CKEDITOR.currentInstance) {
    CKEDITOR.currentInstance.config.stylesSet = "mystyles";
}

When I load the page containing the CK Editor, the style drop down contains the default style set, not the custom one I defined.

Does anyone know how to achieve this?

Upvotes: 1

Views: 484

Answers (4)

SMSGavin
SMSGavin

Reputation: 80

Here is how I solved my issue. I added the following to styles.js:

CKEDITOR.stylesSet.add("my-styles", [
    { name: "Paragraph", element: "p" },
    { name: "Heading 1", element: "h1" }
]);

Then, in the master page for the area of my site that needs to use the "my-styles" style set, I added:

<script>window.ckstyleset = "my-styles"</script>

Finally, in config.js I added:

var styleset = window.ckstyleset ? window.ckstyleset : "default";

config.stylesSet = styleset;

Using this approach I was able to customise the styles listed in the drop down depending on what master page was is use.

Upvotes: 0

JanH
JanH

Reputation: 519

Well, it's just javascript after all, so you can simply check the url in some if statement or in some switch-case and then apply styles you need. Do you need some code example? You should be able to find many of them on the internet :)

Upvotes: 0

Kristian Bortnik
Kristian Bortnik

Reputation: 838

Here's the documentation you need to read.

The dropdown styles are defined in CMS\CMSAdminControls\CKeditor\styles.js, such as:

{ name: 'Italic Title',     element: 'h2', styles: { 'font-style': 'italic' } },

You define the name of the style (the name appears in the dropdown), and then the element and style(s) that should be applied.

After editing the file, make sure you clear your browser cache. As most Kentico admin interface pages are nested and iframe'd, the caching is pretty agressive, and your styles might not appear until cache is cleared.

Upvotes: 0

Martin Makarsky
Martin Makarsky

Reputation: 2650

If I remember it right you need to define your new toolbarset in config.js (CMSAdminControls/CKEditor/config.js) dropdown.

Something like:

config.toolbar_Basic = [
['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'InsertLink', 'Unlink']
];

The other thing - you need to add new option to this dropdown in Webparts application > EditableText webpart> Properties > HTMLAreaToolbar > DataSource enter image description here

Upvotes: 0

Related Questions