-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to output raw text in mjml-react? #41
Comments
Hey, Try the following code: function Raw({ html }) {
return React.createElement('mj-raw', {
dangerouslySetInnerHTML: {
__html: html
}
});
}
<Mjml>
<MjmlBody>
<Raw html={`{{now format="YYYY"}}`} />
</MjmlBody>
</Mjml> It worked for me. 🤔 |
Works! Although I wish it was built in so a hack like this isn't necessary. Thanks! |
@mastertheblaster the above solution works as far as preventing escaping, but i realized the rendered html retains the
becomes this mjml: Do you see the same thing on your end? |
Hey @kprokopczyk, The issue you describe is related to In your usecase i would try a little bit different approach: function Raw({ tag, html }) {
return React.createElement(tag || 'mj-raw', {
dangerouslySetInnerHTML: {
__html: html
}
});
}
<Mjml>
<MjmlBody>
<Raw html={`{{now format="YYYY"}}`} />
<MjmlText>
<Raw tag="span" html={`{{now format="YYYY"}}`} />
</MjmlText>
</MjmlBody>
</Mjml> |
I have added the import { MjmlHtml } from 'mjml-react/extensions';
<MjmlHtml tag="span" html={`{{now format="YYYY"}}`} /> |
Weird question, @kdallmeyer-sr why would you pass to something like handlebars? import format from 'date-fns';
<MjmlText>{format(new Date(), 'YYYY')}</MjmlText> |
Its a good question, not a weird one! The ESP we use uses handlebars to fill in user properties. We use MJML as a template to generate an html+handlebars template for the ESP. Previously we had to use their WYSIWYG to generate templates or handcode. Using MJML allowed us a third option that makes it much easier for engineers. Hoped that answered your question. |
Hi - bumping this - as I could not find anywhere else that addresses this issue.
|
It is react library - use react for this. Otherwise you have two options:
|
Hello,
We are using MGML React to output email templates that will then use handlebars when processing the final email.
For example, we have
now
handlebars function with named parameterformat
. When using React, it escapes the quote in the named parameter and breaks handlebars processing.Neither MjmlText or MjmlRaw work.
outputs
"dangerouslySetInnerHTML" does not work either.
outputs
Any idea on how to do this in React or in MJML-React?
The text was updated successfully, but these errors were encountered: