Render template to variable in expressjs

前端 未结 3 694
耶瑟儿~
耶瑟儿~ 2020-12-16 13:40

Is there a way to render template to a variable instead to output?

res.render(\'list.ejs\', {
    posts: posts
});

something like this

3条回答
  •  独厮守ぢ
    2020-12-16 14:37

    I am quite a newbie on express.js, anyway I am not sure you can access the rendered string that way, although if you look at express' "view.js" source on github (here) you see that it's accepting a callback as second argument, if that may help: you may access the rendered string there.

    Otherwise, I think it's quite easy to patch the code to add a method returning the rendered string without sending it: on line #399 you have the very call that gives the string you are looking for.

提交回复
热议问题