Wiki source code of Configure the Default Editor
Last modified by superadmin on 2026/10/14 10:44
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | Choose the editor that opens for wiki content by writing that choice where [[the resolution chain>>doc:documentation.xs.dev.edit.default-editor-resolution.WebHome]] reads it: the wiki administration, an editor binding object, or ##xwiki.properties##. | ||
| 2 | |||
| 3 | The three routes differ in reach and in who can use them, but they store the same pair: a **data type** with an optional **category**, and the **identifier of an editor**. [[Editors, Data Types and Categories>>doc:documentation.xs.dev.edit.editors-data-types-categories.WebHome]] has the values to choose from. | ||
| 4 | |||
| 5 | 1. **For the whole wiki**, let the administration write the binding for you. Open the wiki administration, go to **Editing** then **WYSIWYG Editor**, pick the editor under **Default WYSIWYG Editor** and save: ((( | ||
| 6 | {{image reference="admin-default-wysiwyg-editor.png" size="extra" alt="The WYSIWYG Editor section of the global administration, under Editing, with CKEditor selected in the Default WYSIWYG Editor drop down list and a Save button below it"/}} | ||
| 7 | |||
| 8 | The list offers the editors registered in the ##wysiwyg## category, and its empty entry removes the setting so that the wiki inherits it again. Saving writes an ##XWiki.EditorBindingClass## object on ##XWiki.XWikiPreferences##, for the data type ##org.xwiki.rendering.syntax.SyntaxContent#wysiwyg##, which is exactly what the next step does by hand. | ||
| 9 | ))) | ||
| 10 | 1. **For one user, or for one page and its children**, add that object yourself. Edit the page that is to carry the setting with the [[Object editor>>doc:documentation.xs.user.base.page.edit.edit-object-editor.WebHome]], add an object of type ##XWiki.EditorBindingClass##, and fill its two properties: ((( | ||
| 11 | |=Property|=Value in this example|=What it is | ||
| 12 | |Data Type|##org.xwiki.rendering.syntax.SyntaxContent#wysiwyg##|the data type, followed by the category | ||
| 13 | |Role Hint|##ckeditor##|the identifier of the editor to use for it | ||
| 14 | |||
| 15 | {{image reference="editor-binding-object.png" size="extra" alt="An EditorBindingClass object on the WebPreferences page of the Handbook space, with Data Type set to org.xwiki.rendering.syntax.SyntaxContent number sign wysiwyg and Role Hint set to ckeditor"/}} | ||
| 16 | |||
| 17 | The page the object sits on is what decides its reach: a **user profile page**, the **##WebPreferences##** page of a page, or **##XWiki.XWikiPreferences##**. [[Default Editor Resolution>>doc:documentation.xs.dev.edit.default-editor-resolution.WebHome]] says how far each of the three reaches, and which one wins when several apply. | ||
| 18 | |||
| 19 | {{warning}} | ||
| 20 | Name the category in **Data Type**. The visual editor reads ##org.xwiki.rendering.syntax.SyntaxContent#wysiwyg## and the wiki editor reads ##org.xwiki.rendering.syntax.SyntaxContent#text##, while the bare ##org.xwiki.rendering.syntax.SyntaxContent## is read only when the editor is looked up without a category. A binding written in the bare form therefore leaves both the visual and the wiki editor exactly as they were. | ||
| 21 | {{/warning}} | ||
| 22 | ))) | ||
| 23 | 1. **For the whole instance**, write the binding in ##xwiki.properties##. The file ships four of these keys, none of them for the ##wysiwyg## category, so nothing in it chooses the visual editor until a line is added: ((( | ||
| 24 | {{code language="properties"}} | ||
| 25 | # edit.defaultEditor.org.xwiki.rendering.syntax.SyntaxContent=text | ||
| 26 | # edit.defaultEditor.org.xwiki.rendering.syntax.SyntaxContent#text=text | ||
| 27 | # edit.defaultEditor.org.xwiki.rendering.block.XDOM=text | ||
| 28 | # edit.defaultEditor.org.xwiki.rendering.block.XDOM#text=text | ||
| 29 | {{/code}} | ||
| 30 | |||
| 31 | Add the line the category needs, uncommented: | ||
| 32 | |||
| 33 | {{code language="properties"}} | ||
| 34 | edit.defaultEditor.org.xwiki.rendering.syntax.SyntaxContent#wysiwyg=ckeditor | ||
| 35 | {{/code}} | ||
| 36 | |||
| 37 | This route is the only one of the three that is not editable from the wiki, and it applies to the whole instance. | ||
| 38 | ))) | ||
| 39 | 1. Check the result where the setting applies: edit a page covered by it, and the editor you chose is the one that opens. ((( | ||
| 40 | {{image reference="configured-editor-rendered.png" size="extra" alt="A page of the Handbook space opened for editing, showing the CKEditor toolbar above the page content"/}} | ||
| 41 | |||
| 42 | What is configured for that page, as opposed to what the chain falls back to, is readable from a wiki page in the same scope, and comes back empty when the scope carries no binding of its own: | ||
| 43 | |||
| 44 | {{code language="velocity"}} | ||
| 45 | {{velocity}} | ||
| 46 | $services.edit.syntaxContent.getDefaultEditorId('wysiwyg') | ||
| 47 | {{/velocity}} | ||
| 48 | {{/code}} | ||
| 49 | ))) |