<p>As with most questions and problems with Redactor, the answer to this should probably be: don't do it in Redactor.</p>

<p>You could just add a new block type to your Matrix field that does just one thing: add the <code>div</code> tag (or close it, if there's an open one). Another possibility is to do this all programatically, check if it is the first or the last block of a specific type and conditionally add the markup to wrap them in your div.</p>

<p>Have a look at the discussion here, to read more about these solutions:<br>
<a href="https://craftcms.stackexchange.com/q/6732/125">Solution for Matrix-within-Matrix (or More Robust Table Fields)</a></p>

<p>And if that's still not flexible enough, you could also have a <a href="https://github.com/engram-design/SuperTable" rel="nofollow noreferrer">Super Table</a> within you Matrix (within a Super Table, within...).</p>

CC BY-SA 3.0
2015-10-30T08:30:00.803Z
2015-10-30T08:30:00.803Z
2017-04-13T12:51:00.253Z
carlcs
<p>I have a Rich Text Field within a Matrix block. I need to add a div around a section of content but can't do this in the template because it's within multiple Matrix blocks.  Solution would be to add it directly into the Rich Text field in code view but it strips out the div and replaces with p tags on save?</p>

<p>I've tried <a href="https://craftcms.stackexchange.com/questions/10500/div-being-replaced-by-p-tags-in-redactor-rich-text-editor">this suggestion</a> but it didn't work.</p>

<matrix><richtext>
Div being removed from Rich Text Field
# Div being removed from Rich Text Field

(Asked by: username_0 on 2015-10-29)

I have a Rich Text Field within a Matrix block. I need to add a div around a section of content but can't do this in the template because it's within multiple Matrix blocks. Solution would be to add it directly into the Rich Text field in code view but it strips out the div and replaces with p tags on save?

I've tried [this suggestion](https://craftcms.stackexchange.com/questions/10500/div-being-replaced-by-p-tags-in-redactor-rich-text-editor) but it didn't work.

**Tags:** matrix, richtext


---

## 1 answers

### Answer by username_1 on 2015-10-30. Score: 1

As with most questions and problems with Redactor, the answer to this should probably be: don't do it in Redactor.

You could just add a new block type to your Matrix field that does just one thing: add the `div` tag (or close it, if there's an open one). Another possibility is to do this all programatically, check if it is the first or the last block of a specific type and conditionally add the markup to wrap them in your div.

Have a look at the discussion here, to read more about these solutions:  
[Solution for Matrix-within-Matrix (or More Robust Table Fields)](https://craftcms.stackexchange.com/q/6732/125)

And if that's still not flexible enough, you could also have a [Super Table](https://github.com/engram-design/SuperTable) within you Matrix (within a Super Table, within...).


---

