如何在 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/