MJML - Template Interpolation, Dynamic Data, Context

前端 未结 1 1080
無奈伤痛
無奈伤痛 2021-02-20 15:28

After a lot of searches, I am having difficulties in finding how:

  1. MJML handles dynamic data and template interpolations

I was expecting something l

相关标签:
1条回答
  • 2021-02-20 15:50

    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);
    
    0 讨论(0)
提交回复
热议问题