Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jade/Pug if else condition usage

Tags:

node.js

pug

I'm sending a date to a .jade file from my .js file using Node.js. When the #{date} field is false, it executes the else and print man as it's answer. What could be going wrong?

if #{date} == false
  | #{date}
else
  | man
like image 218
Kumar Kailash Avatar asked Feb 07 '13 06:02

Kumar Kailash


2 Answers

If date is false, do you want to output the string 'man'? If yes, your if and else statements are the wrong way around...

How about:

if date
  = date
else
  | man

or even:

| #{date ? date : 'man'}

or simply:

| #{date || 'man'}
like image 151
Mike Causer Avatar answered Oct 21 '22 01:10

Mike Causer


Within if expression you write plain variable names, without #{...}

if date == false
  | #{date}
else
  | man
like image 32
Marc Avatar answered Oct 21 '22 02:10

Marc