有条件地包含在Jade + Express中 [英] Conditional Include in Jade + Express
本文介绍了有条件地包含在Jade + Express中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果在玉中对"include"使用-else语句,该怎么用?
How can one use if -else statement on "include" in jade??
例如,如果我有两个单独的导航栏模板navbar.jade和navbar_notloggedin.jade
For example, if I have two separate navigation bar templates navbar.jade and 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语句将检查是否定义了变量,而不是是否为空字符串.但是,我假设您没有为用户存储空字符串值.
The if statement will check whether the variable is defined or not, not whether it is an empty string or not. However, I assume you are not storing empty string values for user.
这篇关于有条件地包含在Jade + Express中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文