handlebars-lang / handlebars.js

Minimal templating on steroids.
http://handlebarsjs.com
MIT License
17.96k stars 2.04k forks source link

How do you actually use knownHelpers or include partials when precompiling? #1896

Closed tnwanna closed 1 year ago

tnwanna commented 1 year ago

I know this is for issues, but I think the docs for precompiling could use significantly more details or at least examples of what each option looks like. For instance, for the knownHelpers option it says

https://handlebarsjs.com/api-reference/compilation.html#handlebars-compile-template-options

Hash containing list of helpers that are known to exist (truthy) at template execution time. Passing this allows the compiler to optimize a number of cases. Builtin helpers are automatically included in this list and may be omitted by setting that value to false.

I'm not quite sure what that means. Is it an array of helper names? Or, just making this up, an array of [{"<helper name>: true/false},...]? I can't seem to even find any examples on stackoverflow and while I could look through the code for the precompile function, that shouldn't have to be the case.

And the same with partials, which aren't explained. Does calling Handlebars.registerPartial before precompiling include them? Or is there no way official way to do so (because I've seen some hacks/workarounds)?