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 but it didn't work.


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)

And if that's still not flexible enough, you could also have a Super Table within you Matrix (within a Super Table, within...).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.