Jade 内联条件 [英] Jade Inline Conditional
本文介绍了Jade 内联条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 Jade 模板引擎使除数组中的第一个元素之外的所有元素都具有 CSS 类.
I'm trying to make everything apart from the first element in an array have a CSS class using the Jade templating engine.
我希望我可以这样做,但没有运气.有什么建议吗?
I was hoping I could do it like this, but no luck. Any suggestions?
- each sense, i in entry.senses
div(class="span13 #{ if (i != 0) 'offset3' }")
... a tonne of subsequent stuff
我知道我可以按如下方式包装代码,但据我了解 Jade 的嵌套规则起作用,我必须复制代码或将其提取到 Mixin 或其他东西中.
I know I could wrap the code as below, but as far as I understand Jade's nesting rules to work, I'd have to duplicate the code or extract it to a Mixin or something.
- each sense, i in entry.senses
- if (i == 0)
.span13
... a tonne of subsequent stuff
- else
.span13.offset3
... identical subsequent stuff
有没有更好的方法来做到这一点?
Is there a better way of doing this?
推荐答案
您可以改为这样做:
- each sense, i in entry.senses
- var klass = (i === 0 ? 'span13' : 'span13 offset3')
div(class=klass)
... a tonne of subsequent stuff
这篇关于Jade 内联条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文