我可以在EJS模板(在JMVC中)中使用条件语句吗? [英] Can I use conditional statements with EJS templates (in JMVC)?

查看:74
本文介绍了我可以在EJS模板(在JMVC中)中使用条件语句吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

,如果是,语法是什么?
我的目标是,如果有多个注释,则在注释前面加上一个。在JMVC应用程序的jQuery.ejs模板中。以下休息。我找不到条件文档...

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 breaks. I can't find any docs for conditionals...

<%=commentsNumber%> comment<% if (commentsNumber > 1) { %> s <% } %>


推荐答案

对于偶然发现此问题的其他人,您也可以使用条件语句中的ejs参数/属性:

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

recipes.js文件:

recipes.js File:

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

recipes.ejs文件:

recipes.ejs File:

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

这篇关于我可以在EJS模板(在JMVC中)中使用条件语句吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆