Repository navigation
Is it possible to have dynamic props in json templates for email editor #3783
|
In my project, we have 100 or so email templates all set up with I have been studying the docs for the email editor and I think that might work for us. But in the docs, I cannot find any reference or mention of how to handle dynamic parts in the template edited by a user. Lets say the first line of an email is:
Is there any way to embed it in the template so users can still edit the template while keeping the props? Other templating engines sometimes allow such variables like Is there any primitive extension offered by the react email editor for this? |
Replies: 1 comment 2 replies
|
There's no built-in variable or merge-tag feature in the editor docs that I could find, but the editor is built for exactly this kind of extension. You can add a small custom node for variables with A rough sketch of an inline variable node: import { EmailNode } from '@react-email/editor/core';
const Variable = EmailNode.create({
name: 'variable',
group: 'inline',
inline: true,
atom: true,
addAttributes() {
return { name: { default: 'userName' }, fallback: { default: '' } };
},
renderHTML({ node }) {
return ['span', { 'data-variable': node.attrs.name, class: 'variable-chip' }, `{{${node.attrs.name}}}`];
},
renderToReactEmail({ node }) {
return <>{`{{${node.attrs.name}}}`}</>;
},
});Your editors insert it from a slash command or button ( If you'd rather keep real React props, |
There's no built-in variable or merge-tag feature in the editor docs that I could find, but the editor is built for exactly this kind of extension. You can add a small custom node for variables with
EmailNode, which is TipTap'sNodeplus arenderToReactEmail()method (see "Custom extensions" and theEmailNodeAPI reference).A rough sketch of an inline variable node: