MJML - 模板插值、动态数据、上下文 [英] MJML - Template Interpolation, Dynamic Data, Context
本文介绍了MJML - 模板插值、动态数据、上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
经过大量搜索,我很难找到方法:
After a lot of searches, I am having difficulties in finding how:
- MJML 处理动态数据和模板插值
- MJML handles dynamic data and template interpolations
我期待的是:
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 不处理任何模板.如果您需要模板,请使用把手等模板引擎呈现为 MJML.
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);
这篇关于MJML - 模板插值、动态数据、上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文