Jade uses what I refer to as "implicit enumeration" - it enumerates values in a list simply by adding one more variable, i
, than there are values to unpack: for item, i in list_like
(For dicts you can do for key, val in dict_like
)
Shown below is your example using tuple unpacking and "implicit enumeration" together, tested with PyJade 2.0.2
- var selected_index = 0
- var tabs = [('hello', '/world'), ('citizens', '/please/respect_your_mother'), ('thank_you', '/bye')]
ul
// unpack `tabs` and tack on the variable `i` to hold the current idx
for label, link, i in tabs
li(class="selected" if (i == selected_index) else "")
a(href="#{link}") #{label}
NOTE: As more commonly seen in "standard" Jade code, as of this writing, PyJade does NOT support the ternary operator for assignment. (variable= (condition)? value_if_true : value_if_false
)