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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With