Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jade - Template Engine: How to check if a variable exists

I'm currently using Jade on a new project. I want to render a page and check if a certain variable is available.

app.js:

app.get('/register', function(req, res){     res.render('register', {         locals: {           title: 'Register',           text: 'Register as a user.',         }       }); }); 

register.jade:

- if (username) p= username - else p No Username! 

I always get the following error:

username is not defined 

Any ideas on how I can fix this?

like image 990
mbecker Avatar asked Feb 21 '11 20:02

mbecker


1 Answers

This should work:

- if (typeof(username) !== 'undefined'){   //-do something -} 
like image 139
Chetan Avatar answered Sep 19 '22 10:09

Chetan