Jade Templating with if else条件语句和导航参数

时间:2016-12-22 20:27:47

标签: node.js pug

li()
   a(href="/dashboard")
   span(style = "font-size:16px;" class = "pull-right hidden-xs showopacity glyphicon glyphicon-dashboard")
   |    Dashboard
li(class = "active")
    a(href="#") 
    span(style = "font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-cloud-upload")
    |   Upload
li()
    a(href = "/analyze")
    span(style = "font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-stats")
    |   Analyze
li()
    a(href = "/locate")
    span(style = "font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-file")
    |   Locate

我想使用从node.js文件传递的参数显示所选导航项的活动类。我必须对此模板文件进行哪些更改?

1 个答案:

答案 0 :(得分:0)

li(class = parameter ? "active": "")
   a(href="/dashboard")
   span(style = "font-size:16px;" class = "pull-right hidden-xs showopacity glyphicon glyphicon-dashboard")
   |    Dashboard
li(class = parameter ? "active": "")
    a(href="#") 
    span(style = "font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-cloud-upload")
    |   Upload
li(class = parameter ? "active": "")
    a(href = "/analyze")
    span(style = "font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-stats")
    |   Analyze
li(class = parameter ? "active": "")
    a(href = "/locate")
    span(style = "font-size:16px;" class="pull-right hidden-xs showopacity glyphicon glyphicon-file")
    |   Locate

尝试这是否有效,三元运算符由pug支持