How do I precompile partials for handlebars.js?

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

    Still not sure about precompiling partials, but this is how to call one template from within another template with help from this question: Handlebars helper for template composition

    // instead of {{> partialName}} use {{partial "templateName"}}
    Handlebars.registerHelper('partial', function(templateName,context){
        return new Handlebars.SafeString(Handlebars.templates[templateName](this));
    });
    

    http://jsfiddle.net/EBt8R/

提交回复
热议问题