Shadow133
Shadow133

Reputation: 11

Adding additional content blocks in KeystoneJS with handlebars

I'm using handlebars with KeystoneJS and am trying to extend the main import in the default template. At the moment it only includes the {{{body}}} tag imported through the view plus the partials that I'm using.

Is there any way to add a couple of other imports (i.e. intro content, page title, additional scripts). In the jade version on the demo site it just imports it as a content block. Is this a limitation of handlebars?

Upvotes: 1

Views: 479

Answers (1)

Jeremy Hindle
Jeremy Hindle

Reputation: 170

You can do this with handlebars just fine using partials.

Put your partial in the folder indicated below:

enter image description here

Then in your layout ('default.hbs' in this case) reference the partial like you would normally in handlebars.

<div id="header">
    {{> navigation this}}
</div>
  • The '>' means insert partial.
  • In this case 'navigation' is the partial name in the partials folder.
  • 'this' is the data context. Its what you want to do with the 'locals.data' object passed into handlebars by keystone. Using 'this' will pass the whole lot through whereas doing something like 'locals.data.navigation' would pass the navigation object through to the partial making it directly accessible in the partial (good for DRY).

Hope that helps. The partials specific documentiation for handlebars is here if you are interested in looking into a few more things you can do with scope etc http://handlebarsjs.com/partials.html

Upvotes: 1

Related Questions