Conditional Include in Jade + Express

可紊 提交于 2019-12-07 23:01:48

问题


How can one use if -else statement on "include" in jade??

For example, if I have two separate navigation bar templates navbar.jade and navbar_notloggedin.jade

I would like to do:

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

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

回答1:


You can use,

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

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.



来源:https://stackoverflow.com/questions/11859942/conditional-include-in-jade-express

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!