How do I precompile partials for handlebars.js?

后端 未结 7 1262
心在旅途
心在旅途 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:50

    I found an even better method: precompile all your partials as templates, then right before you use them in your code, add this line:

    Handlebars.partials = Handlebars.templates;
    

    The improvements are 1) it's shorter and 2) it doesn't loose any custom helpers you might pass in when calling the parent template.

提交回复
热议问题