Clips

Compiles a go-to collection of commonly used code snippets, text, and more for quick and easy access.

Click anywhere in the editor and insert something using the Clips button on the toolbar.

Code

<!DOCTYPE html>
<html>
    <head>
        <title>Redactor</title>
        <meta charset="utf-8">

        <!-- css -->
        <link rel="stylesheet" href="/your-folder/redactor.css" />
    </head>
    <body>
        <!-- element -->
        <textarea id="entry">...</textarea>

        <!-- js -->
        <script src="/your-folder/redactor.js"></script>
        <script src="/your-folder/plugins/clips/clips.js"></script>

        <!-- call -->
        <script>
        Redactor('#entry', {
            plugins: ['clips'],
            clips: {
                items: {
                    "lorem-ipsum": {
                        title: 'Lorem ipsum...',
                        html: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
                    },
                    "label-red": {
                        title: 'Red label',
                        html: '<span class="label-red">Label</span>'
                    }
                }
            }
        });
        </script>
    </body>
</html>

Usage

In the example code, you can see that you can insert both plain text and HTML content that has styles or CSS classes. For example, the label-red class in this case can have these styles:


.label-red {
    background: red;
    color: white;
    display: inline-block;
    line-height: 1;
    padding: 4px 10px;
    border-radius: 6px;
}

By default, the plugin only adds its button to the toolbar. To add it to the context bar, enable the context setting:


Redactor('#entry', {
    plugins: ['clips'],
    clips: {
        context: true,
        clips: {
            items: {
                "lorem-ipsum": {
                    title: 'Lorem ipsum...',
                    html: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
                },
                "label-red": {
                    title: 'Red label',
                    html: 'Label'
                }
            }
        }
    }
});