Keystone/Nunjucks , 数据没有传递给模板

Keystone/Nunjucks , data does not pass to template

我正在使用 Keystone JS 和 nunjucks。我有一个功能,可以在应用程序中发送电子邮件。发送电子邮件没有问题,问题是数据没有传递给模板。不适应。

代码

var sendEmail = function (err, results) {
        if (err) return callback(err);
        async.each(results.admins, function (admin, done) {
            new keystone.Email({ templateName: 'enquiry-notification.html', transport: 'mailgun', engine: cons.nunjucks, root: 'templates/emails' }).send({
            }, {

                    apiKey: '',
                    domain: '',
                    title: "Test",
                    author: 'test',
                    body: 'Heeeeeeeeeeeeeeeeeeeeeeeeeeeee',
                    subject: subject,
                    html: '<b>NodeJS Email Tutorial</b>',
                    body: "Helloworld",
                    to: admin.email,
                    text: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaavbbb',
                    host: 'helloworld.com',
                    from: {
                        name: 'Test Mail',
                        email: inquiry.email
                    },
                    inquiry: inquiry,
                    brand: brand,
                }, done);
        }, callback);


    }

模板

<h1>Hi %recipient%</h1>
<p class="text-larger">An enquiry was just submitted to %from.name%:</p>

{% if inquiry.email %}
    <p class="text-larger">From
    {% if inquiry.name.full %}
        <strong>{{ inquiry.name.full }}</strong>
    {% endif %}

{% endif %}

因为根据doc,如果你需要发送locals你需要在.send()方法里面发送:

new Email(/* ... */).send({
    recipient: {
        firstName: 'Max',
        name: 'Stoiber',
    }
}, {/* ... */}, function (err, result) {/* ... */});

所以在你的情况下它将是:

const sendEmail = function (err, results) {
  if (err) return callback(err);
  async.each(results.admins, function (admin, done) {
    new keystone.Email({ templateName: 'enquiry-notification.html', transport: 'mailgun', engine: cons.nunjucks, root: 'templates/emails' })
    .send({
      inquiry: inquiry,
      brand: brand
    }, { /*....*/ }, done);
  }, callback);

}