-
Hi there! I'm working on an email editor using this awesome library. I got stuck when trying to develop a system where the user can create email template with variables and then those variable get replaced. I created a custom private plugin for creating and adding those email template elements. But I'm unsure how to go about substituting them so the user can see them replaced by their actual values and edit them before sending. I faced 2 issues primarily:
How would to go about dealing with this? I've considered pre-parsing the template and substitute the variables, but feels awkward since I don't see any way to do that from the plugin. I also tried, to give different keys to the const components = createPlateComponents({
'template-variable': props => {
return (
<span {...props.attributes}>
<span contentEditable={false}>Template Value</span>
{props.children}
</span>
);
},
'replaced-variable': props => {
return (
<span {...props.attributes}>
<span>Replaced Value</span>
{props.children}
</span>
);
},
}); When declaring the plugin like this: const replace = true;
const plugin = {
pluginKeys: 'template-variable',
deserialize: getTemplateVariableDeserialize(),
serialize: getTemplateVariableSerialize({ substitute }),
renderElement: getRenderElement(replace ? 'replaced-variable' : 'template-variable'),
inlineTypes: getPlatePluginTypes('template-variable'),
voidTypes: getPlatePluginTypes('template-variable'),
} But it ignored me altogether when replacing the variable. Thanks ❤️ |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
With a plugin factory you can recreate the plugins, then if you give a new reference to Plate |
Beta Was this translation helpful? Give feedback.
getRenderElement
accepts an array of plugin key, can you trygetRenderElement(['replaced-variable', 'template-variable'])
?With a plugin factory you can recreate the plugins, then if you give a new reference to Plate
plugins
prop, it should update them