pugjs / babel-plugin-transform-react-pug

A plugin for transpiling pug templates to jsx
MIT License
811 stars 47 forks source link

Improvement: if else in atrribute #53

Closed phmngocnghia closed 6 years ago

phmngocnghia commented 6 years ago

Can we have if else in attribute. like this : a( className=if(foo===bar) foo else bar )

Transpile into : <a href={foo===bar? 'foo' : 'bar'} />

ezhlobo commented 6 years ago

@PhmNgocNghia is using of ternary operator enough for you? Like:

a(className=foo === bar ? foo : bar)

It works currently, have you tried?

ForbesLindesay commented 6 years ago

Yes, pug supports arbitrary js expressions for attribute values just like jsx does, so just use a ternary.