How to allow DIV tags in Yii2 Editor

273 Views Asked by At

I installed a blog module that allows me to add blogs to my Yii2 app. Everything works well except the editor. I think Yii2 by default uses redactor. The problem is that when I add code with using the code interface, all DIV tags are converted automatically to P tags. Screenshot of editor

I have checked through the redactor configuration but it does not look like there is a setting to adjust this:

    'redactor' => [
        'class' => 'yii\redactor\RedactorModule',
        'uploadDir' => '@frontend/images/blog/upload',
        'uploadUrl' => '/sites/eop/frontend/images/blog/upload',
        'imageAllowExtensions' => ['jpg', 'png', 'gif', 'svg'],
    ],  

Any idea on where else to look at?

1

There are 1 best solutions below

3
Muhammad Omer Aslam On BEST ANSWER

You need to use the replaceDivs option, and set it to false under the client options. See the below code for an example

<?php echo \yii\redactor\widgets\Redactor::widget(
    [
        'model' => $model,
        'attribute' => 'body',
        'clientOptions' => [
            'replaceDivs' => false
        ]
    ]
);
?>

if you are using an ActiveForm it should be like

<?php echo $form->field($model, 'body')->widget(
    [
        'clientOptions' => [
            'replaceDivs' => false
        ]
    ]
);
?>