Templates

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.

Load the bundle

<script src="/assets/redactor/redactor.js"></script>
<script src="/assets/redactor/plugins/templates/templates.js"></script>

Initialization

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>'
            }
        }
    }
});

Options

  • templates (object | string | false)
    • default false
    • Template source. Object map keyed by id ({ name, html } per entry), or URL string to load JSON. The plugin is inactive when false.
  • icon (string)
    • SVG icon HTML for the toolbar button.
Redactor('#entry', {
    plugins: ['templates'],
    templates: {
        templates: '/api/templates.json'
    }
});

Language strings

en: {
    templates: {
        templates: 'Templates'
    }
}

Events

This plugin does not emit events.

API

insert

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' });