You cannot pass a variable as a partial name in the usual way. There are two possible solutions:
1) If you know all the possible names, you can statically generate a flat template and use it the way you want.
Initial data:
{ "names": [ { "name": "dashboard-one" }, { "name": "dashboard-two" } ] }
Static Pattern:
{{#each names}} \{{#if name.{{name}} }} \{{> sidebar-{{name}} }} \{{/if}} {{/each}}
will produce:
{{#if dashboard-one }} {{> sidebar-dashboard-one }} {{/if}} {{#if dashboard-two }} {{> sidebar-dashboard-two }} {{/if}}
Then you pass the name "dashboard-one" in the context of the template:
{ "name": "dashboard-one" }
and execute a partial sidebar-dashboard-one .
2) Write a user assistant. Handlebars internally use the Handlebars.VM.invokePartial method to invoke partial ones. See how it works .
source share