Reputation: 370
I only want to show dashboard in my ejs template when my session variable person
is not null
or not undefined
.
But it's just showing the dashboard every time. and in my log statement, the person
value is undefined
.
<%= console.log(person); %>
<% if (person !== null || person !== undefined) { %>
<%- include("dashboard"); %>
<% } else { %>
<%- include("login"); %>
<% } %>
What could be the proper way to do it?
Upvotes: 0
Views: 312
Reputation: 370
It can be done in following way:
<%- include(person !== null && person !== undefined ? "dashboard" : "login"); %>
Upvotes: 0
Reputation: 2204
I'm not sure but can you try changing the if statement to
<% if (person) { %>
It will simple return true if person is not null or undefined
Upvotes: 1