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

前端 未结 7 506
误落风尘
误落风尘 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 19:50

    Just making code shorter you can use ES6 features. The same things can be written as

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

    And the Templeate can be render as the same!

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

提交回复
热议问题