I have a template which has a header, footer, and sidebar; I want to separate them into separate files and include them in the main template. previously I was using PHP, and it was very easy to do this by include()
or required()
function, but since I am using node.js instead of PHP I don't know how to do that.
Asked
Active
Viewed 1,819 times
0

M.A.O.2
- 37
- 9
3 Answers
2
<script>
$(document).ready(function (e) {
$( "#header" ).load( "header.html" );
$( "#sidebar" ).load( "sidebar.html" );
$( "#footer" ).load( "footer.html" );
});
</script>
You can use jquery for that.

Supun Abesekara
- 708
- 7
- 32
0
You can use W3schools library to achieve this easily.
add this script in your HTML
<script src="https://www.w3schools.com/lib/w3.js"></script>
Call w3.includeHTML() to include the HTML:
<script>
w3.includeHTML();
</script>
full example
<!DOCTYPE html>
<html>
<script src="https://www.w3schools.com/lib/w3.js"></script>
<body>
<div w3-include-html="content.html"></div>
<script>
w3.includeHTML();
</script>
</body>
</html>

Imran Rafique
- 1,986
- 2
- 12
- 14