Jade ternary operator add element
pug
Solution
No. There is no ternary operator (that I know of!) in Jade.As it turns out, there is a ternary operator. However, to shorten your code, what you could do is declare blocks and use them in your if/else sections. While this technically adds lines to your code, I think this helps you with your problem of long if/else statements.
Using your example:
block x_view
td
a(href="/#{foo.x}/foobar") View
block dash
td -
block y_hello
td
a(href="/#{foo.y}/hello") Hello
tbody
each foo in bar
tr
td= foo.name
if foo.x
block x_view
else
block dash
if foo.y
block y_hello
else
block dash
Problem
Wondering if there is a way to write a ternary, or shorter form of if statement, which adds the 'a' element to the table cell when the if is satisfied. I tried this, but it doesn't work: ``` td= foo.x ? a(href="/#{foo.x}/foobar") View : '-' ``` The following does work, but is quite long winded and untidy.. ``` tbody each foo in bar tr td= foo.name if foo.x td a(href="/#{foo.x}/foobar") View else td - if foo.y td a(href="/#{foo.y}/hello") Hello else td - ``` Thanks