I'm a beginner in node.js.
My index.ejs
file has an included header.ejs
file. Everything works well except that I cant pass values to the variable status
in header.ejs
.
<html>
.
.
<title> <%= title %> </title>
.
.
<% include ../partial/header.ejs %>
.
.
</html>
<header>
.
.
<p>logged in status: <%= status %> </p>
.
.
</header>
.
.
.
app.get('/', function(req, res)
{
// not working :(
res.render('index', {
"status":"loggedin",
"title":"home"
});
});
.
.
.
There's somewhat of a mess with your structure.
<title>
should be within <head>
. <p>
should be within <body>
. <head>
and <header>
tags in your templates. You can learn about the difference here .Here's an example I expect will work for you:
index.ejs:
<html>
<head>
<title> <%= title %> </title>
</head>
<body>
<% include ../partial/header %>
</body>
</html>
header.ejs:
<p>logged in status: <%= status %> </p>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.