This is the code
<% if( !title || title!=="login"){ %>
<div class="dashboard-main-cont">
<div class="navigation-option">
<a class="btn btn-primary navbtn" href="/admin/bookings">Booking Requests</a>
<a class="btn btn-primary navbtn" href="/admin/showprojects">Manage Projects</a>
<a class="btn btn-primary navbtn" href="#">Calculation Requests</a>
<a class="btn btn-primary navbtn" href="#">Manage Blogs</a>
<form action="/admin/logout" method="POST">
<button class="btn btn-danger">Logout</button>
</form>
</div>
<% } %>
I am not passing a title value but I have put "!" in front of "title", but I am still getting this error:
title is not defined
How to solve this problem? Thanks in advance!!
You probably should define title first using keywords like let or const. This error is coming because you have not defined it.
So, I think that "title" needs to at least be declared for it to be able to work with the "!".
You could render the file by passing title: undefined on the render information. That way, the variable is defined as "undefined", but at least it is defined.
On the snippet below, by defining the variable, it can be used by the bang to detect if it is a "positive" value, as for the second "if", it throws an error.
const declared_title = undefined
console.log("foo")
if( !declared_title || declared_title !== "login") {
console.log("bar")
}
console.log("fizz")
if( !undeclared_title || undeclared_title !== "login") {
console.log("buzz")
}
As for the render call, it should look something like this
res.render('your_page',{ title: undefined });