Answers.Body: <p>Have you considered using the <a href="https://docs.craftcms.com/v3/matrix-fields.html" rel="nofollow noreferrer">Matrix</a> field type? You could create a block for rich text, then a block for a contact form (or whatever widget).</p>
  
  <p>You could probably achieve what you're asking with a plugin but in my experience doing things like this in Redacter are prone to weirdness/bugginess (especially when in the hands of a client).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-22T12:39:11.420Z
Answers.Text: I would rather avoid that approach, as the content is logically a single unit: an article. At the moment, I use page breaks, which works fine for site-wide widgets (like ad units), but not so well for entry-specific widgets (like sponsors).
Answers.UserDisplayName: nicbou
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-22T12:47:41.450Z
Answers.Text: Perhaps I miss-understand but there needn't be any difference in the way it displays on the front end ie. the content can still look like:
  <article>
      <p>You rich text output</p>
      <form>Your form</form>
      <p>More rich text</p>
  </article>
Answers.UserDisplayName: dmatthams
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-22T14:25:44.783Z
Answers.Text: Cutting the content in pieces with a Matrix field seems like the wrong approach. The content (e.g. an article) is a single unit and should be a single unit in the database. The widget is more akin to a bit of template: it contains server-side logic like a CSRF tag. It's not a static element.
Answers.UserDisplayName: nicbou
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-22T14:44:56.857Z
Answers.Text: In that case, it's a case of extending redactor.
Answers.UserDisplayName: dmatthams
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-22T16:09:11.067Z
Answers.Text: @NicolasBouliane Cutting the article up into matrix blocks is an _excellent_ way to approach this problem. A matrix field is still a single field, I don’t understand what the hang up is.
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-22T16:11:06.587Z
Answers.Text: This article describes the purpose and architecture very well... https://nystudio107.com/blog/creating-a-content-builder-in-craft-cms
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-23T05:45:05.857Z
Answers.Text: Lindsey, you are right. I have simply misunderstood what a matrix field was. I've toyed around with it today and it's exactly what I need. Is there an easy way to migrate the content from a rich text field to a matrix field?
Answers.UserDisplayName: nicbou
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-22T10:24:15.363Z
Answers.LastActivityDate: 2019-08-22T10:24:15.363Z
Answers.UserDisplayName: dmatthams
Body: <p>I want to insert widgets in arbitrary positions in one of my rich text fields. A good example would be a contact form inserted in the middle of the content. These widgets would be ad units, forms and similar dynamically rendered templates.</p>
  
  <p>I know about the widget plugin for Redactor, but this is only suitable for static HTML. I need something a bit closer to an <code>{% include %}</code> tag.</p>
  
  <p>How would you approach this problem?</p>
  
  <p>I considered using WordPress-like <code>[insert-widget-here]</code> tags, or perhaps iFrames, but I'd prefer a more elegant solution.</p>
  
Tags: <templating><editor>
Title: How to insert widgets in Rich Text field
ThreadText: # How to insert widgets in Rich Text field
  
  (Asked by: username_0 on 2019-08-22)
  
  I want to insert widgets in arbitrary positions in one of my rich text fields. A good example would be a contact form inserted in the middle of the content. These widgets would be ad units, forms and similar dynamically rendered templates.
  
  I know about the widget plugin for Redactor, but this is only suitable for static HTML. I need something a bit closer to an `{% include %}` tag.
  
  How would you approach this problem?
  
  I considered using WordPress-like `[insert-widget-here]` tags, or perhaps iFrames, but I'd prefer a more elegant solution.
  
  **Tags:** templating, editor
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-08-22. Score: 3 | Accepted answer
  
  Have you considered using the [Matrix](https://docs.craftcms.com/v3/matrix-fields.html) field type? You could create a block for rich text, then a block for a contact form (or whatever widget).
  
  You could probably achieve what you're asking with a plugin but in my experience doing things like this in Redacter are prone to weirdness/bugginess (especially when in the hands of a client).
  
  > **Comments:**
  > **username_0**: I would rather avoid that approach, as the content is logically a single unit: an article. At the moment, I use page breaks, which works fine for site-wide widgets (like ad units), but not so well for entry-specific widgets (like sponsors).  
  > **username_1**: Perhaps I miss-understand but there needn't be any difference in the way it displays on the front end ie. the content can still look like: <article>     <p>You rich text output</p>     <form>Your form</form>     <p>More rich text</p> </article>  
  > **username_0**: Cutting the content in pieces with a Matrix field seems like the wrong approach. The content (e.g. an article) is a single unit and should be a single unit in the database. The widget is more akin to a bit of template: it contains server-side logic like a CSRF tag. It's not a static element.  
  > **username_1**: In that case, it's a case of extending redactor.  
  > **username_2**: @NicolasBouliane Cutting the article up into matrix blocks is an _excellent_ way to approach this problem. A matrix field is still a single field, I don’t understand what the hang up is.  
  > **username_2**: This article describes the purpose and architecture very well... https://nystudio107.com/blog/creating-a-content-builder-in-craft-cms  
  > **username_0**: username_2, you are right. I have simply misunderstood what a matrix field was. I've toyed around with it today and it's exactly what I need. Is there an easy way to migrate the content from a rich text field to a matrix field?  
  
  ---
  
  