-
-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Feature request
What is motivation or use case for adding/changing the behavior?
Handlebars supports helpers to extend its functionality. For example, there are no comparison or coalesce operators besides the if statement, which expects a boolean value. This limitation leads to boilerplate code that converts every statement like {{#if (eq value "apple")}} to template({isApple: value === "apple"}) and {{#if isApple}}. Using it with HTML controls to set selected in <select><option ... makes the situation even worse.
Additionally, handlebars-loader supports this feature via the helperDirs option. Implementing this would improve feature parity between the two.
Describe the solution you'd like
I would love for helpers to be compiled into the template function, allowing them to be used in imported templates.
Side note: handlebars-loader doesn’t allow inline scripts in the configuration like this plugin does. I think this is a reasonable tradeoff to enable compiling helpers into the template.
Side note 2: It seems like this plugin doesn’t support ESM helpers:
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/vagrant/workspace/website/src/handlebars/coalesce.js from /home/vagrant/workspace/website/.cache/pnpm/virtual-store-dir/[email protected][email protected][email protected]/node_modules/html-bundler-webpack-plugin/src/Loader/Preprocessors/Handlebars/index.js not supported.
Instead change the require of coalesce.js in /home/vagrant/workspace/website/.cache/pnpm/virtual-store-dir/[email protected][email protected][email protected]/node_modules/html-bundler-webpack-plugin/src/Loader/Preprocessors/Handlebars/index.js to a dynamic import() which is available in all CommonJS modules.
Describe alternatives you've considered
- Introducing
is*variables. - Using
handlebars-loaderwithout inheritance.
Appreciation for the useful project
- [⭐] After the feature is implemented, do not forget to give a star ⭐
Thank you!