Configure N1ED dynamically using API

The visual configuration is the best way to configure N1ED, but it is for static configuration only. What if you need to pass some dynamically calculated parameters? For example, you want to have different file directories for different users or apply some UI changes for some user roles (i. e. enable or disable some features).

The solution - to use the API of your editor to do this. Depending on what editor do you use as a base (CKEditor or TinyMCE), the way of passing parameters differs, but the parameters are the same, and each visual configuration item is linked to some parameter inside the config.

For example when you see some parameter like this:

Example parameter

Some parameter for sample

API parameter
example.param
Type
string
Default
null

Some description

in the documentation, this means you can pass this parameter to override the cloud N1ED config you define using dashboard or configuration editor.

Passing parameters to TinyMCE

If you use TinyMCE 4 or TinyMCE 5 as a base editor, there is one correct place to pass parameters inside: tinymce.init(params) function.

You already use it to initialize TinyMCE on some textarea or div tag. The only you need to do is to pass the new parameter into this function. For example:

tinymce.init({
    selector: "#editor",
    plugins: "n1ed",
    example: {
        param: "123"
    }
});  

Passing parameters to CKEditor

There are two ways to inject a new parameter to the config of CKEditor. The first way is equivalent to TinyMCE: you pass the new parameter into initialization function CKEditor.replace(selector, params) like this:

CKEDITOR.replace("#editor", {
    extraPlugins: "N1ED-editor",
    example: {
        param: "123"
    }
});  

The second way is used when you call replace() function without parameters and define them in your config file. In this case, you should do something like this inside this file:

CKEDITOR.editorConfig = function( config ) {
    config.extraPlugins: "N1ED-editor";
    config.example = {
        param: "123"
    };
};