Jade conditional (if/else) to add class to div inline

jstevens13 picture jstevens13 · Jan 3, 2013 · Viewed 48.2k times · Source

Is there a way to do this inline in a jade template?

if(typeof fromEdit != 'undefined')
   div#demo.collapse.in
else
   div#demo.collapse

Would like to do this conditional check "inline" and the result would add the .in to the end of the div if fromEdit exists.

Answer

Dogbert picture Dogbert · Jan 3, 2013

This works:

div#demo.collapse(class=typeof fromEdit === "undefined" ? "" : "in")

Try it out here.