Wxcc
Wxcc

Reputation: 19

How to insert an handlebarsjs file inside an other

I want to have something like this:

<body>

{{> header}}

</body>

Where header is referencing to header.hbs (main.hbs is at the same directory)

I'm creating the partial with:

exphbs.create("header", "{{header}}")

but The partial header could not be found

Upvotes: 0

Views: 2114

Answers (2)

ALPHA
ALPHA

Reputation: 1155

try this, in here the header means the file name

<body>

{{> header}}

</body>

Upvotes: 0

kkenney
kkenney

Reputation: 36

Reusable hbs templates are called "partials". You can write these in a separate directory to your page (or "views") templates.

Tell Express where these are stored in your app entry point file - usually app.js or index.js with

Handlebars.registerPartials('../path/to/partials/directory')

Then you can use any of your partials templates in your views with below syntax

{{>partialName}}

See docs for further info:

https://handlebarsjs.com/guide/partials.html#basic-partials

Upvotes: 2

Related Questions