What is the proper way to check for existence of variable in an EJS template (using ExpressJS)?
The same way you would do it with anything in js, typeof foo == 'undefined'
, or since "locals" is the name of the object containing them, you can do if (locals.foo)
. It's just raw js :p
Try prepending the variable with locals
Example: if(locals.user){}
<% if (locals.user) { %>
// Your logic goes here
<% } %>