handlebars-loader icon indicating copy to clipboard operation
handlebars-loader copied to clipboard

@index referencing index.js not the index of the each helper

Open Zashy opened this issue 10 years ago • 8 comments

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.

Zashy avatar Mar 16 '16 21:03 Zashy

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.

pcardune avatar Mar 19 '16 00:03 pcardune

I just ran into this myself. Any workarounds or resolutions yet?

craig-jennings avatar May 16 '16 15:05 craig-jennings

nope :(

pcardune avatar May 24 '16 15:05 pcardune

Just ran into this problem as well. Did anyone find any workarounds for this?

andrei-cacio avatar Jul 21 '16 14:07 andrei-cacio

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.

Zashy avatar Jul 21 '16 16:07 Zashy

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

indieveed avatar Oct 14 '16 12:10 indieveed

FWIW, when using #each with an array, using @key gives me the array index, which may suffice for anyone dealing with this issue.

mAAdhaTTah avatar Oct 20 '16 19:10 mAAdhaTTah

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 .

pcardune avatar Oct 25 '16 18:10 pcardune