I'm using a Node.js Server with Express-Framework installed and have a problem combining two different html-files.
I have a basic template.html file with a <div id="content"> in it. Now I want to include content.html within this div before sending the data to the client.
How can this be done?
I like to use EJS because it's the most straight-forward templating language, but the same idea applies for jade or whatever you might use. To enable this in express after running npm install ejs:
app.engine('.ejs', require('ejs').__express);
When you send your response, run:
res.render('content.html.ejs');
Spit your template.html into views/header.html.ejs and views/footer.html.ejs, and include them in views/content.html.ejs like this:
<% include header.ejs %>
Content Here
<% include footer.ejs %>