handlebars.jspartials

How to add dynamic value in handlebar partial path


In my file I have a call to an external handlebars partial like this

{{> docs/setup/install }}

This works fine. 'install' is the name of the partial.

I want to dynamically call other files using the partial helper. Something like this

{{> docs/setup/{{filename}} }}

This obviously is not working. It is an example of what I am trying to achieve.

How do I pass the dynamic {{filename}} to the include partial helper?

I am on node and using the express-hbs library.


Solution

  • You may want to use "subexpressions".

    Refer to the documentation available here : https://handlebarsjs.com/guide/partials.html#dynamic-partials