@index referencing index.js not the index of the each helper
When converting from the grunt handlebars to webpack I've run into an issue.
I have a file that is using the each helper. Inside the each I'm using slide-{{@index}}. Once this is compiled it seems to be using the following instead.
return " <div class=\"row "slide-"
+ alias1(require("C:\\projects\\connect\\src\\js\\components\\summary\\fr\\index.js").call(depth0,{"name":"index","hash":{},"data":data}))
+ " slider"
In the same directory as the handlebars template is an index.js. Seems that it is referencing this instead of the each helper's @index.
I think I have managed to write a failing test for this scenario. Now trying to figure out the best way to fix this. Handlebars doesn't seem to distinguish between builtin helpers, which start with @ and custom helpers. So when we are doing name lookups to add the require calls, there doesn't appear to be a way to tell if that came from a {{@index}} or {{index}}. In the latter case, having a require would be the right thing to do.
I will see if I can figure it out.
I just ran into this myself. Any workarounds or resolutions yet?
nope :(
Just ran into this problem as well. Did anyone find any workarounds for this?
The only workaround I found is not having an index.js in that directory. Which luckily worked for my use case as the index.js wasn't being used in that specific directory.
@pcardune don't you think that it is better to always resolve index as builtin helper and state it in the docs? Seems like it is a rare case to use helpers named index, but the builtin helper is used a lot.
FWIW, when using #each with an array, using @key gives me the array index, which may suffice for anyone dealing with this issue.
If someone wants to submit a pull request to change this behavior, I will happily review it. On Thu, Oct 20, 2016 at 12:58 PM James DiGioia [email protected] wrote:
FWIW, when using #each with an array, using @key gives me the array index, which may suffice for anyone dealing with this issue.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pcardune/handlebars-loader/issues/87#issuecomment-255211445, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHnm5hYj1v-TkFDb6bFlK7rG_1x6G6cks5q18fxgaJpZM4HybCs .