如何将视图渲染为字符串? [英] How to render a view to a string?
本文介绍了如何将视图渲染为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在sailsjs控制器/动作中呈现特定视图,该视图应作为电子邮件发送。
I want to render a specific view in a sailsjs controller/action which should be sent out as email.
我有以下示例操作:
function registerAction(req, res) {
// handle user registration
// email user
sendEmail({
to: newUser.email,
subject: "Welcome",
text: /* VIEW RENDER HERE */
});
// render view to the user
return res.view({
user: newUser
});
}
如何使用sailsjs提供的工具渲染视图模板,以便我不需要硬编码电子邮件文本或使用其他库?
How can I render a view-template with the tools sailsjs provides so that I don't need to hardcode an email text or use other libraries?
提前致谢!
推荐答案
快递' res.render()
仍然是在 res
对象中可访问。
Express' res.render()
is still accessible in your res
object.
function registerAction(req, res) {
// handle user registration
res.render('/path/to/view', function (err, html) {
// email user
sendEmail({
to: newUser.email,
subject: "Welcome",
text: html
});
}
// render view to the user
return res.view({
user: newUser
});
}
这篇关于如何将视图渲染为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文