Question: Dragging blocks into a Text block?
See original GitHub issueThis is not a bug but an implementation question. If this is not the right place to ask these questions, please let me know.
We’re working on an implementation where we want to use GrapesJS to allow users to create an e-mail template. As part of this implementation we are working to create mail-merge functionality: we’ve introduced the concept op ‘merge-fields’ or ‘placeholders’ which we will replace with the proper values on the server side. This means we send over the components
JSON structure and turn it into HTML server-side, replacing values as we go.
So, as an example, one of our users might enter the text: Hello <<username>>
and we’ll replace that merge-field <<username>>
with the proper field.
But, we haven’t been able to implement this this way quite yet as we’re not able to drag these blocks into a Text block. We can only drag it around it. So, for now we’re extending the RTE with a merge-field ‘inline block’ ( <input type=text readonly class=mergeField data-isMergefield=1 />
) and creating a merge-field block with the same HTML in the block manager. Implementing a DomComponent type to recognize it offers a method to configure it. But it feels suboptimal, we’d really like to be able to drag that mergefield block onto the right place in the textfield.
To allow this, I imagine GrapesJS would have to be able to grab the textNode and split it in to (atleast) two textnodes and a tag for the merge-field but I’m not sure where to start with this. Could you advise as to how we might implement this?
Issue Analytics
- State:
- Created 6 years ago
- Comments:42 (13 by maintainers)
Have you checked API-Rich-Text-Editor? You can add a custom action like this
Probably in the next release, this feature will be available.
So
textable
will be just another property, this will allow any component to be dropped inside Text components. Here is the code of the component from the example above: