'include of header and footer in ejs file not working

guys I'm working on a node/express app in cloud 9. https://webdevcamp-miatech.c9users.io/ however, the include files in my home.ejs file are not working. I have a header.ejs and footer.ejs which I'm including into my home.ejs file. But when I go call the default route "/" home. It gives me. Here's the app on c9.io https://ide.c9.io/miatech/webdevcamp this error message.

Error: Could not find include include file.
    at getIncludePath (/home/ubuntu/workspace/EJSDemo/node_modules/ejs/lib/ejs.js:152:13)
    at includeSource (/home/ubuntu/workspace/EJSDemo/node_modules/ejs/lib/ejs.js:276:17)
    at /home/ubuntu/workspace/EJSDemo/node_modules/ejs/lib/ejs.js:629:26
    at Array.forEach (native)
    at Object.generateSource (/home/ubuntu/workspace/EJSDemo/node_modules/ejs/lib/ejs.js:605:15)
    at Object.compile (/home/ubuntu/workspace/EJSDemo/node_modules/ejs/lib/ejs.js:509:12)
    at Object.compile (/home/ubuntu/workspace/EJSDemo/node_modules/ejs/lib/ejs.js:358:16)
    at handleCache (/home/ubuntu/workspace/EJSDemo/node_modules/ejs/lib/ejs.js:201:18)
    at tryHandleCache (/home/ubuntu/workspace/EJSDemo/node_modules/ejs/lib/ejs.js:223:14)
    at View.exports.renderFile [as engine] (/home/ubuntu/workspace/EJSDemo/node_modules/ejs/lib/ejs.js:437:10)

If I remove the include of footer and header from home.ejs it gets fixed. So It has to be either the way I'm including it or the path. If anyone can help. Thanks home.ejs

<% include ./partials/header %>
<h1>Hello World</h1>
<img src="http://lorempixel.com/400/200/">
<% include ./partials/footer %>

header.ejs

<!DOCTYPE html>
<html>
<head>
    <title>EJSDemo</title>
    <link rel="stylesheet" type="text/css" href="/app.css">
</head>
<body>

footer.ejs

        <p>trademark 2018</p>
    </body>
</html>

finally my app.js

var express = require("express");
var app = express();

//tell express to serve the content of public dir
app.use(express.static("public"));
app.set("view engine", "ejs");

//default app route
app.get("/", function(req, res) {
    res.render("home.ejs");
});

// /fallinlove route
app.get("/fallinlove/:thing", function(req, res) {
    var thing = req.params.thing;
    //rendering love.ejs and passing variable to template
    res.render("love.ejs", {thingVar:thing});
});

// /post route
app.get("/posts", function(req, res) {
    var posts = [
            {title: "Post 1 ", author: "Charlie"},
            {title: "My adorable pet bunny", author: "Susy"},
            {title: "Can you believe this pomsky?", author: "Colt"}
        ]
    res.render("posts.ejs", {posts: posts});
});


//start server
app.listen(process.env.PORT, process.env.IP, function() {
    console.log("server started!..");
});


Solution 1:[1]

I encountered the same problem and this new(er) EJS syntax works just fine.

// <%- include("partials/header") %>
// <%- include("partials/footer") %>

Solution 2:[2]

To anyone facing that problem, the new syntax is

<%- include('partials/header') %>

Tip: you should include:

app.set("view engine", "ejs");

Solution 3:[3]

I was facing same problem but following code works for me

<%- include('header'); -%>

<!-- your HTML code --> 

<%- include('footer'); -%>

Solution 4:[4]

I can't say without seeing your folder structure, but the most likely problem might be the path you give in the <% include ./partials/header.ejs %>. By giving this path, you're telling ejs that the partials folder and the home.ejs file are in the same directory.

Edit your question to show us the way your folders are organized. We can rule that issue out once you do so.

EDIT: Do the includes in the other templates work? Or is it just the home.ejs?

Solution 5:[5]

I got my code working and showing like this right now:

and

 <%- include('header'); -%>
<%- include('footer'); -%>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DavidW
Solution 2 f.khantsis
Solution 3 Manish Nakar
Solution 4 Sphoorthy Nutulapati
Solution 5 Jakub Kurdziel