web-tip.top
WTT

Change Markdown to Wysiwyg editor in RainLab.Blog

13.07.2024

To change the Markdown editor to Wysiwyg in Rainlab.Blog, you need to add the following code to your plugin in Plugin.php:

public function extendRainlabBlog(){
    Event::listen('backend.form.extendFields', function($widget) {
        // Extend only the Posts controller or Post model
        if (!$widget->getController() instanceof \RainLab\Blog\Controllers\Posts ||
            !$widget->model instanceof \RainLab\Blog\Models\Post){
            return;
        }
        // Update content field
        $widget->addSecondaryTabFields([
            'content' => [
                'tab' => 'rainlab.blog::lang.post.tab_edit',
                'type' => 'richeditor',
                'size' => 'huge',
                'stretch' => 'true'
            ]
        ]);
    });
}

And then call the method in boot():

public function boot(){
    $this->extendRainlabBlog();
}