What does “res.render” do, and what does the html file look like?

后端 未结 2 473
说谎
说谎 2020-12-02 20:38

What does res.render do, and what does the html file look like?

My end goal is to load arbitrary comma-separated-values fr

2条回答
  •  孤街浪徒
    2020-12-02 21:15

    What does res.render do and what does the html file look like?

    res.render() function compiles your template (please don't use ejs), inserts locals there, and creates html output out of those two things.


    Answering Edit 2 part.

    // here you set that all templates are located in `/views` directory
    app.set('views', __dirname + '/views');
    
    // here you set that you're using `ejs` template engine, and the
    // default extension is `ejs`
    app.set('view engine', 'ejs');
    
    // here you render `orders` template
    response.render("orders", {orders: orders_json});
    

    So, the template path is views/ (first part) + orders (second part) + .ejs (third part) === views/orders.ejs


    Anyway, express.js documentation is good for what it does. It is API reference, not a "how to use node.js" book.

提交回复
热议问题