Adds a drop-down list of predefined placeholders that you can insert into the editor.
Redactor version: 8.2.6
This example has predefined HTML content with placeholders.
Text inside double curly brackets are transformed to a placeholder {{user_name}} to User name
redactor_placeholder.js somewhere after redactor.js.redactor_placeholder.css, or copy styles to your stylesheet. This just creates the toolbar icon, and styles the placeholder spans.[{name: '', value: ''}, ...] to your textareaplaceholders plugin to your redactor instance.See the example below:
// Placeholder object
var placeholders = [
{
"name": "user_name", // Placeholder's id.
"value": "User name" // Placeholder's name, visible to user.
},
...
];
// Attach placeholder to textareas, before redactor init.
$('#redactor').data('placeholders', placeholders);
// Init redactor with placeholder plugin.
$('#redactor').redactor({
plugins: ['placeholders']
});
Sadly Redactor has no beforeSave callback, therefore you have to transform the placeholder spans back to text manually by calling the plugin's getTransformedHtml method. See the example below:
$('#redactor').data('redactor').getTransformedHtml();