Reputation: 355
I am trying to render my partials into views but I keep getting the error
Error: Could not find the include file "('partials/header')"
My files structure is like so:
-MAIN FOLDER
-controllers
-userController
-staticPagesController
-postsController
-models
posts
users
-public
stylesheets
-views
user
all user ejs files
post
all post ejs files
site
all staticpage ejs files
partials
all partials
-index.js
I tried adding my partials folder to each view subfolder, but it didn't help anything.
I also thought maybe my controllers weren't seeing the path properly and added ejs = require(ejs
) to each controller path but it didn't fix it either.
my views look like this:
<%- include ('partials/header') %>
<h1>Homepage</h1>
and my index.js looks like this:
//Application global constants
const express = require(`express`);
const mongoose = require(`mongoose`);
const bodyParser = require(`body-parser`);
const ejs = require('ejs');
const _ = require(`lodash`);
//Initiate Express
const app = express();
app.use(express.static(`public`));
//Initiate EJS engine
app.set(`view engine`, `ejs`);
app.engine('html', require('ejs').renderFile);
//Initiate body parser
app.use(bodyParser.urlencoded({extended: true}));
//Set express static files
//ROUTING
staticPages = require(`./controllers/staticPageController`);
postPages = require(`./controllers/postController`);
userPages = require(`./controllers/userController`);
Upvotes: 0
Views: 409
Reputation: 1
Add the 'views' folder declaration
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
Upvotes: 0
Reputation: 1307
Would you please try to add below code:
var express = require('express');
var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
Also include the header like(Remove the space specially):
<%- include('partials/header') %>
Upvotes: 0