Anand Sunderraman
Anand Sunderraman

Reputation: 8128

Node.js Jade Conditional rendering

I want to conditionally render my html.

I have a variable by name addr_2 which i am setting via a rest service and passing it on to the jade template like

res.render('jade_file',{addr_2 : 'some_value'});

There could be scenario where i set the value of the variable addr_2 as 'NULL'

On the jade file I want to render the value of addr_2 only when it is not equal to 'NULL'

I tried the following code but it does not work

   | (#{addr_2} === 'NULL') ? '' : #{addr_2} br

Upvotes: 3

Views: 3085

Answers (1)

Ted Avery
Ted Avery

Reputation: 5689

Make reference to passed in variables like addr_2 without any curly tags or hash symbols when you are evaluating them.

if (typeof(addr_2) !== undefined && addr_2 != null) {
  | #{addr_2}
}

Upvotes: 5

Related Questions