Pierre
Pierre

Reputation: 123

Including an html file into another html file using Handlebars.js

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?

Upvotes: 5

Views: 9559

Answers (1)

Nick Bartlett
Nick Bartlett

Reputation: 4975

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.

Upvotes: 10

Related Questions