Can I use conditional statements with EJS templates (in JMVC)?

前端 未结 7 504
误落风尘
误落风尘 2020-11-30 19:16

and if yes, what is the syntax? My goal is to prepend an \'s\' to the word \'comment\' when there is more than one. in an jQuery.ejs template in a JMVC app. The following br

7条回答
  •  星月不相逢
    2020-11-30 20:01

    For others that stumble on this, you can also use ejs params/props in conditional statements:

    recipes.js File:

    app.get("/recipes", function(req, res) {
        res.render("recipes.ejs", {
            recipes: recipes
        });
    });
    

    recipes.ejs File:

    <%if (recipes.length > 0) { %>
    // Do something with more than 1 recipe
    <% } %>
    

提交回复
热议问题