经过大量搜索,
我在寻找方法上遇到困难:
我期待的是这样的:
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>
最佳答案
MJML不处理任何模板。如果需要模板,请使用模板引擎(例如 Handlebars )渲染为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);