How do I precompile partials for handlebars.js?

后端 未结 7 1241
心在旅途
心在旅途 2021-02-01 03:10

I\'m using handlebars.js and I want to start precompiling everything, but I can\'t seem to find a way to precompile the partials. The majority of my templates are actually parti

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-01 03:51

    I am using HandleBars v3.0.3 and I have partial and not partial templates pre-compiled in one file.

    This thread is little bit confusing so I am summarizing the working solution.

    • Don't use -p operator while pre-compiling.
    • Don't register partial template by Handlebars.registerPartial('myPartial', '{{name}}');
    • use Nathan's suggestion of mapping partial object to templates object by Handlebars.partials = Handlebars.templates;
    • Refer partial template by name {{> name}}

提交回复
热议问题