Mahdi
Mahdi

Reputation: 141

Include partials in hjs

In ejs we can include a partials in a template in this way (suppose that header.hjs is in view/partials path):

<% include ./partials/header %> 

How can I do this in hjs?

Upvotes: 0

Views: 257

Answers (1)

Mahdi
Mahdi

Reputation: 141

I got the answer from this link (the sample in this link uses layout and partials and I just used partials for my case to include a navBar):

The solution is:

  1. Add your partial in views (e.g views\navBarPartial.hjs).
  2. In app.js (server.js) define the partial:

    app.set('partials', { navBarPartial: 'navBarPartial' } );

  3. In the view which you need this partial, include it:

<html>
<head>    
</head>
<body>
    ...
    {{> navBarPartial}}
    ...
</body>
</html>

Upvotes: 0

Related Questions