1

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.

1 Answer 1

3

Have you considered using the Matrix 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).

7
  • 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).
    – nicbou
    Commented Aug 22, 2019 at 12:39
  • 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>
    – dmatthams
    Commented Aug 22, 2019 at 12:47
  • 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.
    – nicbou
    Commented Aug 22, 2019 at 14:25
  • In that case, it's a case of extending redactor.
    – dmatthams
    Commented Aug 22, 2019 at 14:44
  • @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.
    – Lindsey D
    Commented Aug 22, 2019 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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