Content block: cancel div to p replacement

Permalink 2 users found helpful

Need some help with tweaking content block. I need to disable div to p replacement. Redactor official docs list 'replaceDivs' as option for that. I've added
replaceDivs: false
to Redactor call in add.php and edit.php in application/blocks/content/ but nothing changes, something still overrides added divs. Any ideas?

Thanks a million in advance for any hint!

View Replies: View Best Answer
Jupiter replied on at Permalink Best Answer Reply
hi gorillabrand,

please look at below link...
I hope this will help you

gorillabrand replied on at Permalink Reply
hi Jupiter!

Thanks a lot, but nope, this link relates to the pre-5.7 version which used TinyMCE editor. Now C5 uses Redactor by

gorillabrand replied on at Permalink Reply
Jupiter, it helped!
I used logic from your link in redactor.js and it worked like charm!
Thank you!
Darragi replied on at Permalink Reply
Hi gorillabrand,

Can you post the solution please? because i have same problem.

That may help and save time for other people also.

Thanks in advance
Darragi replied on at Permalink Reply

Found it!
Not as mentioned in official redactor doc, the correct option is:
convertDivs: false,

Hope that helps other

craigrundle replied on at Permalink Reply

did not work for me.

replaceDivs: false,

WillemAnchor replied on at Permalink Reply
you may also want to set:

linebreaks: true,
paragraphize: false,
aruben replied on at Permalink Reply
Hi gorillabrand,

Perhaps it's too late, but this can help someone else.

You need to customize the Redactor Editor to use breaklines instead of paragraphs.
After, it's possible to add the DIV tag inside using the html view.
But if you insert an element inside (text, image...), it breaks the DIV, except if the content of the DIV is inside P (ie: DIV P ... /P /DIV).
Or, we must use the linebreaks options (use BR instead of P). But with this last option, you can't use P tag, because all of them are converted into BR !
It's the same issue with SECTION tag or others.

Conclusion: use the HTML block instead of Redactor to add DIV, or use the grid (better).

If you want to use DIV inside Redactor, look at
adding the WillemAnchor's comment:

1.Make application/src/Editor/RedactorEditor.php
2.Override editor binding from application/bootstrap/app.php

In file app.php, add:

Core::bindShared('editor', function() { 
   return new \Application\Src\Editor\RedactorEditor(); 

In file RedactorEditor.php, add:

namespace Application\Src\Editor;
class RedactorEditor extends \Concrete\Core\Editor\RedactorEditor
   protected function getEditor($key, $content = null, $options = array())
      // Stop converting divs to paragraphs
      $options['replaceDivs'] = false;
      /*Don't use these 2 options, insert a P tag inside the DIV instead
      // Use line breaks <br> instead of paragraphs <p> when user presses Return key (because <p> is semantic)
      $options['linebreaks'] = true;
      // Marks up text with paragraphs, if it hasn't been marked up with paragraphs yet
      $options['paragraphize'] = false;   //=true if linebreaks=false
      return parent::getEditor($key, $content, $options);

(tested with Redactor 10.0.9 and 10.2.1 - ie: C5 and

I think it's better to use a specific theme page to add SECTION tags, the grid system to add DIV, with Redactor inside to put the text, instead of using DIV inside Redactor.

I hope this will help you.

syedmushran replied on at Permalink Reply
Hi ARuben,

I was able to fix the problem of div tags being replaced with p tags. Now I have another problem, <span> tags in my code are being removed. Could you please help me with this?

Syed Mushran
aruben replied on at Permalink Reply

For <span> tag, in my tests, they are not removed. So, perhaps you have changed the code and it breaks the span tag.
I also notice that it don't accept imbricated <span>: it remove one.

Perhaps, spending time with Redactor now is not a good idea: (
Redactor seem to be stay in v5.7 only.