I was trying to figure out how to render a view inside a view, as I was stuck with this issue.
I was using Node.js platform with ejs template engine.
My index.ejs file has an included header.ejs file.
Everything works well except that I can't pass values to the variable status in header.ejs.
Here is my abstract code...
The solution is as easy as this.
Just remove .ejs extension from the include command.
I spent at least an entire night to figure it out.
Horrible Effects of Misplaced Extensions ;)
My index.ejs file has an included header.ejs file.
Everything works well except that I can't pass values to the variable status in header.ejs.
Here is my abstract code...
index.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
. | |
. | |
<title> <%= title %> </title> | |
. | |
. | |
<% include ../partial/header.ejs %> | |
. | |
. | |
</html> |
header.ejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<header> | |
. | |
. | |
<p>logged in status: <%= status %> </p> | |
. | |
. | |
</header> |
app.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
. | |
. | |
app.get('/', function(req, res) | |
{ | |
// not working :( | |
res.render('index', { | |
"status":"loggedin", | |
"title":"home" | |
}); | |
}); | |
. | |
. | |
. |
The most funniest solution ever!
Just remove .ejs extension from the include command.
I spent at least an entire night to figure it out.
I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly.
ReplyDeleteEthical Hacking Course in Chennai
Hacking Course in Chennai
Hacking Classes in Chennai
Blue Prism Training in Chennai
CCNA Course in Chennai
Cloud Computing Training in Chennai
Ethical Hacking Training in OMR