After a lot of searches, I am having difficulties in finding how:
I was expecting something like:
import { mjml2html } from 'mjml';
const context = {
message: 'Hello World'
};
const view = mjml2html(template, context);
<mjml>
<mj-body>
<mj-container>
<mj-section>
<mj-column>
<mj-text>{message}</mj-text>
</mj-column>
</mj-section>
</mj-container>
</mj-body>
</mjml>
Click on "Compile to HTML" and look at the right panel to see how your email will look like on different devices. When you are done editing your MJML, click on the "HTML" toggle button on the top left of your screen to see the responsive HTML generated by the engine: all you have to do now is save it!
What is MJML? MJML stands for Mailjet Markup Language and originated from a group of developers at Mailjet (now Pathwire) who set out to help developers code emails in a simpler and more efficient way. So, they developed a markup language that simplifies the complexity of responsive HTML and automatically generates it.
mj-style. This tag allows you to set CSS styles that will be applied to the HTML in your MJML document as well as the HTML outputted. The CSS styles will be added to the head of the rendered HTML by default, but can also be inlined by using the inline="inline" attribute.
MJML doesn't handle any templating. If you want templates, use a template engine such as handlebars to render to MJML.
import { compile } from 'handlebars';
import { mjml2html } from 'mjml';
const template = compile(`
<mjml>
<mj-body>
<mj-container>
<mj-section>
<mj-column>
<mj-text>{{message}}</mj-text>
</mj-column>
</mj-section>
</mj-container>
</mj-body>
</mjml>
`);
const context = {
message: 'Hello World'
};
const mjml = template(context);
const html = mjml2html(mjml);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With