In PHP, it's easy to include a file in another one to avoid redundancy of the code using the include
keyword. Is there a similar solution in Node.JS using Handlebars.JS?
Templates The recommended way of adding templates to your page is by including them in <script> tags with a special type. The type attribute is important, otherwise the browser will attempt to parse them as JavaScript (which they are not). The templates have an easy to grasp syntax.
EJS is way faster than Jade and handlebars. EJS has a really smart error handling mechanism built right into it. It points out to you, the line numbers on which an error has occurred so that you don't end up looking through the whole template file wasting your time in searching for bugs.
From your question it sounds like you are looking for handlebars partials. For an example check out https://github.com/donpark/hbs/tree/master/examples/partial.
In short, you'd have something which looked like:
index.hbs:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Your Website</title>
</head>
<body>
{{> header}}
</body>
</html>
where {{> header}}
is referencing the header.hbs
partial.
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