CKEditor plugins that convert Content Templates into Widgets for Drupal 8.
Convert CKEditor Content Templates into Widgets., (*1)
Start using CKEditor Template Widget in three steps., (*2)
Download latest CKEditor Template Widget module from Github or via Composer and enable it as usual., (*3)
composer require outlawplz/ckeditor_template_widget
Define a CKEditor plugin in your libraries/
folder that converts a
template into a widget., (*4)
# Plug-in location /libraries/templatewidget/plugin.js
Add a content that uses a template and enjoy your new content editor experience., (*5)
That's it. You're all set to start using CKEditor Template Widget., (*6)
Suppose you have defined a template that prints the following HTML., (*7)
<div class="lt-50 clearfix"> <div class="lt-50__clm lt-50__clm--left"> <p>Your content...</p> </div> <div class="lt-50__clm lt-50__clm--right"> <p>Your content...</p> </div> </div>
Create the plug-in file libraries/templatewidget/plugin.js
as follow. Here
we're adding a new CKEditor plug-in called templatewidget
. Inside the plug-in
we add a new widget using the function editor.widget.add()
; we can define
multiple widgets in a single plug-in., (*8)
CKEDITOR.plugins.add( 'templatewidget', { requires: 'widget,templates', init: function ( editor ) { editor.widgets.add( 'lt_50', { // Define a new widget. editables: { // Define editable parts. left: { selector: '.lt-50__clm--left' }, right: { selector: '.lt-50__clm--right' } }, upcast: function( element ) { // Convert the template into a widget. return element.name == 'div' && element.hasClass( 'lt-50' ); } } ); } } );
That's it. Now we can try to use the template in CKEditor, and verify that the widget is working., (*9)