The multi-root editor type is an editor type that features multiple, separate editable areas.
The main difference between using a multi-root editor and using multiple separate editors (like in the inline editor demo) is the fact that in a multi-root editor all editable areas belong to the same editor instance share the same configuration, toolbar and the undo stack, and produce one document.
Gone traveling
Monthly travel news and inspiration
Destination of the Month
Valletta
The capital city of Malta is the top destination this summer. It’s home to cutting-edge contemporary architecture, baroque masterpieces, delicious local cuisine, and at least 8 months of sun. It’s also a top destination for filmmakers, so you can take a tour through locations familiar to you from Game of Thrones, Gladiator, Troy, and many more.
The three greatest things you learn from traveling
Check out the Quick start guide to learn more about implementing this kind of editor. You will find implementation steps there. You can see this example editor’s code below.
<div id="toolbar"></div>
<!--
Wrapping the structure inside a pair of
contenteditable="true" + contenteditable="false" elements
is required to provide proper caret handling when
using arrow keys at the start and end of an editable area.
You can skip them if you don't want to move the
caret between editable areas using arrow keys.
!-->
<div contenteditable="true">
<div contenteditable="false">
<div class="editor">
<div id="header">
Header content is inserted here.
</div>
</div>
<div class="editor">
<div id="content">
Main content is inserted here.
</div>
</div>
<div class="boxes">
<div class="box box-left editor">
<div id="left-side">
Left-side box content is inserted here.
</div>
</div>
<div class="box box-right editor">
<div id="right-side">
Right-side box content is inserted here.
</div>
</div>
</div>
</div>
</div>
<style>
.editor {
border: #ccced1 1px solid;
margin-top: 10px;
}
.boxes {
margin-top: 10px;
display: flex;
}
.box {
margin-top: 0px;
width: 50%;
}
/*
Make the editable "fill" the whole box.
The box will grow if the other box grows too.
This makes the whole box "clickable".
*/
.box .ck-editor__editable {
height: 100%;
}
.box-left {
margin-right: 10px;
}
/*
When toolbar receives this class, it becomes sticky.
If the toolbar would be scrolled outside of the visible area,
instead it is kept at the top edge of the window.
*/
#toolbar.sticky {
position: sticky;
top: 0px;
z-index: 10;
}
</style>
Please note that setting and reading the editor data is different for multi-root editor.
Pass an object when setting the editor data
Setting the data using editor.setData():
editor.setData( {
header: '<p>Content for header part.</p>',
content: '<p>Content for main part.</p>',
leftSide: '<p>Content for left-side box.</p>',
rightSide: '<p>Content for right-side box.</p>'
} );
Setting the data through config.initialData:
MultiRootEditor.create(
{
header: document.querySelector( '#header' ),
content: document.querySelector( '#content' ),
leftSide: document.querySelector( '#left-side' ),
rightSide: document.querySelector( '#right-side' )
},
{
initialData: {
header: '<p>Content for header part.</p>',
content: '<p>Content for main part.</p>',
leftSide: '<p>Content for left-side box.</p>',
rightSide: '<p>Content for right-side box.</p>'
}
}
);
Learn more about using the multi-root editor in its API documentation.
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing?
Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features.
We appreciate your feedback to help us ensure its accuracy and completeness.