Variable

Adds toolbar and addbar buttons for inserting template variables as plain text wrapped in configurable delimiters (default [% Name %]).

Click Variable in the toolbar or addbar and pick a variable name. The wrapped text is inserted at the caret.

Load the bundle

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

Initialization

const app = Redactor('#entry', {
    plugins: ['variable']
});

Options

  • items (string[])
    • default ['Name', 'Lastname', 'Email']
    • Variable names shown in the dropdown. The plugin is inactive when items is falsy.
  • start (string)
    • default '[% '
    • Opening delimiter wrapped around the variable name.
  • end (string)
    • default ' %]'
    • Closing delimiter wrapped around the variable name.
  • context (boolean)
    • default false
    • When true, adds the button to the context toolbar as well.
  • icon (string)
    • SVG icon HTML for the toolbar and addbar buttons.
Redactor('#entry', {
    plugins: ['variable'],
    variable: {
        items: ['First name', 'Email', 'Order ID'],
        start: '{{ ',
        end: ' }}'
    }
});

Language strings

en: {
    variable: {
        title: 'Variable'
    }
}

Events

This plugin does not emit events.

API

add

Inserts a wrapped variable at the caret and closes the dropdown.

Parameters:

  • variable (string) — variable name from items.
app.variable.add({ variable: 'Email' });