Adds an addbar button for inserting HTML snippets loaded from a URL or a static object. Snippets are inserted at the caret without replacing the whole document.
Open the addbar and choose Snippets, then pick an entry from the list.
<script src="/assets/redactor/redactor.js"></script>
<script src="/assets/redactor/plugins/snippets/snippets.js"></script>
const app = Redactor('#entry', {
plugins: ['snippets'],
snippets: {
snippets: {
quote: {
name: 'Quote block',
html: '<blockquote><p>A memorable quote.</p></blockquote>'
}
}
}
});
object | string | false)
false{ name, html } per entry), or URL string to load JSON. The plugin is inactive when false.boolean)
falsetrue, also adds the button to the main toolbar after Add.string)
Redactor('#entry', {
plugins: ['snippets'],
snippets: {
toolbar: true,
snippets: '/api/snippets.json'
}
});
Static object format:
snippets: {
alert: {
name: 'Alert',
html: '<p class="alert">Important message.</p>'
}
}
en: {
snippets: {
snippets: 'Snippets'
}
}
This plugin does not emit events.
Inserts a snippet by key and closes the dropdown.
Parameters:
key (string) — snippet id from the loaded JSON.app.snippets.insert({ key: 'quote' });