I am having an issue with a script in express. I am calling a function that renders a view, on the success of another function. In this project I am utilizing angular, node, express, and ejs as view engine. When I render the view, I unfortunately receive an ejs error of the following:
ReferenceError: /Users/emilywfrancis/Desktop/nodejs-angularjs-sequelizejs/views/about.ejs:5
3| <html ng-app="app">
4| <meta charset="utf-8">
5| <link rel="stylesheet" href="//cdnjs.cloudflare/ajax/libs/font-awesome/3.1.0/css/font-awesome.min.css" />
6| <% include header %>
7| <% include navbar %>
8| <body>
title is not defined
Here is the code:
exports.verifyusers= function(req, res) {
models.user.find({
where: {
email: req.body.email,
password: req.body.password
}
}).then(function(res, user) {
if(user == "user.name") { //if user exists in database
res.render('/about')
};
});
};
I am having an issue with a script in express. I am calling a function that renders a view, on the success of another function. In this project I am utilizing angular, node, express, and ejs as view engine. When I render the view, I unfortunately receive an ejs error of the following:
ReferenceError: /Users/emilywfrancis/Desktop/nodejs-angularjs-sequelizejs/views/about.ejs:5
3| <html ng-app="app">
4| <meta charset="utf-8">
5| <link rel="stylesheet" href="//cdnjs.cloudflare./ajax/libs/font-awesome/3.1.0/css/font-awesome.min.css" />
6| <% include header %>
7| <% include navbar %>
8| <body>
title is not defined
Here is the code:
exports.verifyusers= function(req, res) {
models.user.find({
where: {
email: req.body.email,
password: req.body.password
}
}).then(function(res, user) {
if(user == "user.name") { //if user exists in database
res.render('/about')
};
});
};
Share
Improve this question
edited Jun 9, 2016 at 17:59
Johnathan Mackney
asked Jun 9, 2016 at 17:51
Johnathan MackneyJohnathan Mackney
5452 gold badges6 silver badges13 bronze badges
5
-
Seems like the error is actually in the
header
file. Which properly have something like this:<%= title %>
– Andreas Louv Commented Jun 9, 2016 at 17:53 - yes, there is -- but, I do not understand why this throws an error. – Johnathan Mackney Commented Jun 9, 2016 at 17:56
- Also, the error gives an error pointing to line 5 – Johnathan Mackney Commented Jun 9, 2016 at 17:57
-
I assume the template is piled to JavaScript, something like:
"<title>" + title + "</title>"
. Use:<%= (typeof title != "undefined" ? title : "") %>
and it will properly work, since the generated JavaScript is:"<title>" + (typeof title != "undefined" ? title : "") + "</title>"
– Andreas Louv Commented Jun 9, 2016 at 17:57 - Yes, this works -- thank you. – Johnathan Mackney Commented Jun 9, 2016 at 18:07
2 Answers
Reset to default 13Seems like the error is actually in the header file which proprely contains something like:
<%= title %>
I think changing changing it to the following will work:
<%= (typeof title != "undefined" ? title : "") %>
You need to give your title a value, if not already done. If it is done, then @andlrc answer is correct, but you still want to figure out why it is throwing an error. If not, it is bad practice.
In your server define a variable names title and give it a string. Then expose is to your view.
In this answer you find an example.