Brandon Merritt
Brandon Merritt

Reputation: 31

How can I merge two Handlebars partials before running them through Assemble 0.6.0?

I have two .hbs files. One contains a basic button and the other contains a button bar that utilizes that {{basic-button}}. I want to pull the first .hbs into the second and then have Assemble render it as a file.

I thought it was as easy as registering the basic-button as a partial and passing it to the button bar page. But it looks like I need to run through my .hbs files, render them and then let assemble do its thing.

Is there an equivalent of handlebars.registerpartials i can use in Assemble

Upvotes: 1

Views: 1103

Answers (1)

doowb
doowb

Reputation: 3372

You can register partials with the .partials method...

assemble.partials(['partials/*.hbs']);

Then you can use those partials with normal handlebars syntax (use the filename as the partial name)

{{> basic-button}}

If this isn't what you're looking to do, could you post a repository that I could look at?

Edit

Based on the comments: You can use layouts inside partials (and other template types)

element partials

---
layout: button-bar
---
{{> basic-button }}

button-bar

{% body %}

But I don't think that's what you're trying to accomplish because you probably want multiple "basic-button" partials inside the button bar.

Another option is to use front-matter inside your page to specify the list of buttons and pass it to the partial as the partial's context:

page.hbs

---
buttons:
 - "basic-button"
 - "advanced-button"
 - "menu-button"
---
{{> button-bar buttons}}

Then inside button-bar you can use our built in partial helper to dynamically include the partials from the list:

<ul class="btn-bar">
{{#each this}}
  <li class="btn">{{partial this}}</li>
{{/each}}
</ul>

Hope this helps some.

Upvotes: 1

Related Questions