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

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

问题描述

如果是,语法是什么?我的目标是在有多个评论时在评论"一词前面加上一个s".在 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 params/props:

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天全站免登陆