Search code examples
node.jshandlebars.js

How do I precompile partials for handlebars.js?


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 partials. I tried just treating my them like regular templates, but then calling them as a partial doesn't work.

Is there any way to precompile partials, or, alternatively, call one template from within another template?


Solution

  • 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.