Render HTML on Node.js Express (Include HTML code in another HTML file) -
i'm using node.js server express-framework installed , have problem combining 2 different html-files.
i have basic template.html file <div id="content">
in it. want include content.html within div before sending data client.
how can done?
i use ejs because it's straight-forward templating language, same idea applies jade or whatever might use. enable in express after running npm install ejs
:
app.engine('.ejs', require('ejs').__express);
when send response, run:
res.render('content.html.ejs');
spit template.html views/header.html.ejs
, views/footer.html.ejs
, , include them in views/content.html.ejs
this:
<% include header.ejs %> content here <% include footer.ejs %>