Adds a toolbar button for replacing the entire editor content with a predefined HTML template. Templates are loaded from a URL or a static object.
Click Templates in the toolbar (after Add) and pick a template. The current content is replaced.
<script src="/assets/redactor/redactor.js"></script>
<script src="/assets/redactor/plugins/templates/templates.js"></script>
const app = Redactor('#entry', {
plugins: ['templates'],
templates: {
templates: {
article: {
name: 'Article',
html: '<h1>Title</h1><p>Introduction paragraph.</p><h2>Section</h2><p>Body text.</p>'
}
}
}
});
object | string | false)
false{ name, html } per entry), or URL string to load JSON. The plugin is inactive when false.string)
Redactor('#entry', {
plugins: ['templates'],
templates: {
templates: '/api/templates.json'
}
});
en: {
templates: {
templates: 'Templates'
}
}
This plugin does not emit events.
Replaces editor content with a template by key and closes the dropdown.
Parameters:
key (string) — template id from the loaded JSON.app.templates.insert({ key: 'article' });