node.js - 有条件包含在 Jade + Express 中

标签 node.js express pug

如何在 jade 中的“include”上使用 if -else 语句?

例如,如果我有两个单独的导航栏模板 navbar.jade 和 navbar_notloggedin.jade

我想做:

input(type='hidden', value= user.user)#username

- if(user.user!="")
  include navbar
- else if(user.user=="")
  include navbar_notloggedin 

最佳答案

您可以使用,

-if (user.user)
 include navbar
-else
 include navbar_notloggedin 

if 语句将检查变量是否已定义,而不是检查变量是否为空字符串。但是,我假设您没有为用户存储空字符串值。

关于node.js - 有条件包含在 Jade + Express 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11859942/

相关文章:

javascript - 如何在 mongoose 函数的 if/else block 中来回跳转?

javascript - 退出一系列嵌套回调

javascript - 避免传递请求对象

json - 如何将 JSON 数组从 NodeJS 流式传输到 postgres

css - 如何在 Jade 表格数据元素中使用内联 CSS?

javascript - 基于页面 url 的 Jade 条件?

MySql After Update 触发器执行顺序

javascript - 我们可以使用 NodeMailer 在 NodeJs 中一次发送多少封电子邮件?

javascript - Node.js 从 Jade 加载外部样式表,路径不一致

node.js - Passport js 如何配置某人保持登录状态的时间?