Render template to variable in expressjs

前端 未结 3 696
耶瑟儿~
耶瑟儿~ 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:28

    The easiest way to do that is to pass a callback to res.render, in your example:

    res.render('list.ejs', {posts: posts}, function(err, list){
      // 
    });
    

    But if you want to render partial templates in order to include them in another template you definitely should have a look at view partials.

提交回复
热议问题