所以我试图做他们在这里做的事情MJML - 模板插值,动态数据,上下文但是当我运行时node fun.js
我得到以下错误。
file:///Users/admin/mjml/mjml/fun.mjs:2
import { compile } from 'handlebars'
^^^^^^^
SyntaxError: The requested module 'handlebars' does not provide an export named 'compile'
另外作为旁注,除了上面的链接之外,还有其他使用 MJML 模板的方法
我的代码
import { mjml2html } from 'mjml'
import { compile } from 'handlebars'
/*
Compile an mjml string
*/
const template = compile(
`
<mjml>
<mj-body>
<mj-section background-color="#F0F0F0" padding-bottom="0">
<mj-column padding-left="70px" width="250px">
<mj-text font-style="italic" font-size="22px" color="#626262">watFriends</mj-text>
</mj-column>
<mj-column width="170px">
<mj-image width="30px" src={{logo}} />
</mj-column>
</mj-section>
<mj-section background-color="#FAFAFA">
<mj-column width="400px">
<mj-text font-style="italic" font-size="15px" font-family="Helvetica Neue" color="#626262">
Dear {{firstName}},
</mj-text>
<mj-text color="#525252">{{message}}
</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
`,
)
const context = {
firstName: '',
message: 'hello',
logo: 'logo.png',
}
const mjml = template(context)
const html = mjml2html(mjml)
console.log(html)