Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a value to a plugin in TinyMCE

I've written a TinyMCE plugin and I need to pass a variable to it from my app.

I've tried setting tinymce.activeEditor.my_var = 3; after tinymce.init();. In the plugin, editor.my_var is always undefined.

How can I encode my own variable?

like image 706
roryok Avatar asked Dec 06 '25 05:12

roryok


1 Answers

I found the solution.

When initialising the editor, you can pass it a custom variable, like so.

tinymce.init({
    selector: '#editor_html',
    valid_elements: '*[*]',
    plugins: [
        "my_custom_plugin"
    ],
    my_custom_variable: 'test',
});

then in the plugin you should be able to access the variable with the following code:

editor.getParam("my_custom_variable");

Alternatively, you can use an ajax request to set a session variable, and then have the plugin also perform an ajax request to retrieve the session variable.

like image 74
roryok Avatar answered Dec 07 '25 21:12

roryok