简体   繁体   English

使用meteor和blaze如何将模板转换为电子邮件正文的字符串?

[英]Using meteor and blaze how to convert template to string for an email body?

And how can I set the value of this now? 我现在该如何设置它的值? Ie in js? 即在js? All i see is how to do in handlebars. 我只看到如何做把手。

From Meteorpedia : 来自Meteorpedia:

http://www.meteorpedia.com/read/Blaze_Notes http://www.meteorpedia.com/read/Blaze_Notes

Take a look at "How to render a template to HTML with data" 看看“如何使用数据将模板呈现为HTML”

var toHTMLWithData = function (kind, data) {
    return UI.toHTML(kind.extend({data: function () { return data; }}));
};

Use it like this : 像这样使用它:

var myTemplateAsString=toHTMLWithData(Template.myTemplate,dataContext);

Which is equivalent to previous Spark code : 这相当于以前的Spark代码:

var myTemplateAsString=Template.myTemplate(dataContext);

Currently Meteor does not natively support server side rendering of templates, and since you are sending emails from the server this creates an issue. 目前,Meteor本身不支持服务器端模板的呈现,并且由于您从服务器发送电子邮件,因此会产生问题。 Server side rendering is on the Meteor roadmap, but for now we can use a package. 服务器端渲染在Meteor路线图上,但是现在我们可以使用一个包。 its called "Handlebars-server" and it can be found here: https://atmospherejs.com/package/handlebars-server 它叫做“Handlebars-server”,它可以在这里找到: https//atmospherejs.com/package/handlebars-server

With Handlebars-server you can compile handlebars templates into strings for use in emails. 使用Handlebars-server,您可以将把手模板编译成字符串,以便在电子邮件中使用。 The package's readme should get you started and show you how to set data context. 软件包的自述文件可以帮助您入门并向您展示如何设置数据上下文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM