Custom template for annotations
Providing a custom template is a middle ground between using the default UI and providing a completely custom UI on your own.
This solution gives you the possibility to alter the HTML structure of the comment and suggestion annotations. Thanks to that you can, for example:
- Add new CSS classes or HTML elements to enable more complex styling.
- Re-arrange annotation views.
- Add new UI elements, linked with your custom features.
- Remove UI elements.
It is highly recommended to get familiar with the CKEditor 5 UI library API and guide before continuing.
# Views for comments and suggestions
The view classes used by default by CKEditor 5 collaboration features are:
CommentThreadView
– Generates the UI for comment thread annotations.CommentView
– Presents a single comment.SuggestionThreadView
– Generates the UI for suggestion annotations.
These classes are exported in files in their respective repositories at the following paths:
@ckeditor/ckeditor5-comments/src/comments/ui/view/commentthreadview.js
,@ckeditor/ckeditor5-comments/src/comments/ui/view/commentview.js
,@ckeditor/ckeditor5-track-changes/src/ui/view/suggestionthreadview.js
.
Note that the source code of these files and classes is closed.
It is highly recommended to get familiar with the comment view, comment thread view and the suggestion view API docs before continuing.
# Changing the view template
To use a custom view template, you need to:
- Create a new view class by extending the default view class.
- Provide (or extend) the template by overwriting the
getTemplate()
method. - Set your custom view class through the editor configuration. We recommend setting it in the default configuration in the editor build file.
Creating a custom view:
Setting up configuration in the build file:
Custom comment and suggestion thread views can be set in a similar way:
# Example: Adding a new button
Below is an example of how you can provide a simple custom feature that requires creating a new UI element and additional styling.
The proposed feature should allow for marking some comments as important. An important comment should have a yellow border on the right.
To bring this feature, you need:
- A CSS class to change the border of an important comment.
- A button to toggle the comment model state.
- An integration between the model state and the view template.
# Styling for an important comment
This step is easy. Simply create a CSS file and add a CSS rule:
# Creating a button and adding it to the template
In this step, you will add some new elements to the template.
Keep in mind that you do not need to overwrite the whole template. You can extend it instead.
# Enabling the custom view
The custom view will be enabled in the build file, as shown earlier.
# HTML structure and initialization
The example below uses the “load & save” type of integration.
# Live demo
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.
Bilingual Personality Disorder
This may be the first time you hear about this made-up disorder but it actually isn’t so far from the truth. As recent studies show, the language you speak has more effects on you than you realize. According to the studies, the language a person speaks affects their cognition, behavior, emotions and hence their personality.
This shouldn’t come as a surprise since we already know that different regions of the brain become more active depending on the activity. The structure, information and especially the culture of languages varies substantially and the language a person speaks is an essential element of daily life.
Are we sure we want to use a made-up disorder name?
Why not?