outlawplz / ckeditor_templates
This plugin provides a dialog to offer predefined content templates - with page layout, text formatting and styles.
Installs: 43
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 0
Type:drupal-module
This package is auto-updated.
Last update: 2020-10-04 14:36:57 UTC
README
Drupal 8 custom module that implements Templates plugin in CKEditor.
Quick start
Start using CKEditor Templates in three steps.
- Download latest CKEditor Templates module from Github or via Composer and enable it as usual.
composer require outlawplz/ckeditor_templates
- Download the CKEditor Templates plug-in and copy it to the
libraries/
folder found at Drupal root folder.
# Plug-in location
/libraries/templates/plugin.js
- Edit a text format that uses CKEditor, and enable the Templates plug-in dragging the icon from Available buttons to Active toolbar.
That's it. You're all set to start using CKEditor Templates.
Options
Once the plug-in is enabled, you can specify where to find your templates file editing the plug-in settings. Available options are Name, Path and Replace content.
-
Name: The name of your templates set. In the example below the templates name is
custom
. -
Path: The path to your template file. In the example below the path is
/libraries/custom_templates/custom.templates.js
. -
Replace content: When inserting a template the content should be replaced or not by default.
Templates definition
Templates are defined in JS files. Save your templates file in /libraries
folder or /sites/default/files
folder. In this example the file will be
created into /libraries/custom_templates
folder.
// The name of templates set is 'custom'. CKEDITOR.addTemplates( 'custom', { // Path to the subfolder that contains the preview images. imagesPath: '/libraries/custom_templates/images/', // Template definition. templates: [ { title: 'Custom template', image: 'custom.gif', description: 'Description of my custom template.', html: '<h2>Custom Template</h2>' + '<p>Your text...</p>' }, { title: 'Custom template with image', image: 'custom_image.gif', description: 'Description of my custom template with image.', html: '<h2>Custom Template with Image</h2>' + '<p><img src="/image.png" /></p>', '<p>Your text...</p>' } ] } );