I want to make my webpage modular so that I don´t need to write my stuff again and again. I thought my solution would be the ejs lib. So I´ve using express and ejs that is configured like this:
const app = express();
app.engine('.html', require('ejs').renderFile);
app.set('view engine', 'html');
app.set('views', __dirname + '/wwwroot/views');
My views folder struct looks like that:
wwwroot
static
css
js
views
login
index.html
profile
dashboard.html
templates
inc_header.html
inc_footer.html
My Dashboard has the following content
<% include templates/inc_header.html %>
This is my dashboard
The Header file will not be included. I´ve tried wwwroot/views/templates/header.html and header.html. Nothing works.
app.engine('.html', require('ejs').renderFile);
app.set('view engine', 'html');
app.set('views', __dirname + '/wwwroot/views');
app.use(session({
secret: program.secret || "secret",
resave: true,
saveUninitialized: true
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }))
app.use('/', express.static(path.join(__dirname, '/wwwroot/static/')));
<% include templates/inc_header.html %> This is my dashboard
Looks like the file will not be rendered?
This is from ejs docs:
Includes are relative to the template with the include call.
Since the file from where you include headers is dashboard.html
then the path should be:
<% include ../templates/inc_header %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With