how to include a template with parameters in EJS?

后端 未结 4 2324
无人共我
无人共我 2020-12-09 14:39

As a real beginner in EJS, I have two charts in my html page, so I want to use my partial twice:

<% include partials/spider-chart.ejs %>
4条回答
  •  隐瞒了意图╮
    2020-12-09 15:20

    You can pass single as well as multiple data here is how to do it

    In render funtions

    We can pass multiple data as an object like this

    app.get("/account", function(req, res) {
      res.render("account", {
        name: 'Jon Snow',
        age: 35
      });
    });

    And then can access the data inside account using ejs simple template tags like this

    hello <%= name %>

    your age is <%= age %>

    In Partial views

    Pass the data like this

    <%- include('partials/logout', {name='triyon'}) %>

    And access it like we did above

    logged out <%= name %>

提交回复
热议问题