Using Dynamic Partials in Handlebars

I'm trying to use dynamic partials in Handlebars, using Gulp and gulp-compile-handlebars.

I've seen this roll-your-own solution but I believe that Handlebars now supports dynamic partials out of the box, however I don't understand what the documentation is expecting from me.

In my hbs template I want to specify the name of the partial based on a value in my data, e.g.

"things": [
  {
    "partial_template": "thing1",
    "title": "Thing 1"
  },
  {
    "partial_template": "thing2",
    "title": "Thing 2"
  }
]

With the partials named as:

thing1.hbs, thing2.hbs, etc.

I don't think my requirements need to use subexpressions so was expecting to use the lookup helper as per the Handlebars docs:

{{> (lookup . 'partial_template') }}

But this errors when running Gulp.

Any suggestions as to where I'm going wrong please?

Answers:

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.