27636
27636

Reputation: 237

Configure the user's default choice on tinyMCE toolbar

I am using v5 of TinyMCE. By default, the style selected is 'Paragraph', as shown in this image : [tinyMCE toolbar, as the user sees before he mades any format configuration]

But I know my users will all prefer to use 'Div' style. So I would like 'Div' to be selected by default. The toolbar should therefore appear like in this image : [tinyMCE toolbar, as I want it to be configured by default]

Is it possible ? I haven't find my answer in tinyMCE documentation. Same question if you want for instead "bold" button to be selected by default, etc.

Thank you !

Upvotes: 0

Views: 348

Answers (1)

tinyland
tinyland

Reputation: 271

To replace the default <p> blocks with <div>, use forced_root_block: https://www.tiny.cloud/docs-3x/reference/Configuration3x/Configuration3x@forced_root_block/

tinymce.init({
  // ...
  forced_root_block : 'div'
});

To select the bold button by default, you could use execCommand: https://www.tiny.cloud/docs/api/tinymce/tinymce.editor/#execcommand

tinymce.init({
    // ...
    setup: function(editor) {
      editor.on('init', function() {
          this.execCommand('Bold');
      });
    }
});

Example fiddle combining both: https://fiddle.tiny.cloud/YShaab/1

Upvotes: 2

Related Questions