如何在SailsJS中将视图渲染为字符串?

Igo*_*yev 5 ejs sails.js

在一个控制器中,我想呈现具有特定布局的特定视图以发送带有结果字符串的电子邮件,但我显然不需要向用户显示结果.有没有办法使用我用来渲染视图的EJS引擎来实现这个目的?这是我的一点简化的控制器动作:

  setEmail: function(req, res) {
    var update = {
      activationToken: _getToken(),
      email: req.param('email')
    };

    Profile.update(res.locals.profile.id, update).then(function(profile) {
      res.redirect(profileUrl);
      mailer.sendActivationEmail(
        update.email,
        res.i18n('??????????? ???? ????? ??????????? ?????'),
        emailString); // <=== Here is where I need the string rendered from a view
    });
  },
Run Code Online (Sandbox Code Playgroud)

mdu*_*sch 7

使用view-hook

Profile.update(res.locals.profile.id, update).then(function(profile) {
  res.redirect(profileUrl);

  sails.hooks.views.render("viewname",profile, function(err,html){
     if(err) return console.log(err);

     mailer.sendActivationEmail(
       update.email,
       res.i18n('??????????? ???? ????? ??????????? ?????'),
       html
     );
    })

});
Run Code Online (Sandbox Code Playgroud)

编辑:正确的回调