Passing @index (or other variable) to a helper?

Hi all,
I have some weird problem with Spacebars: I do an #each and a #let myvar=@index. Then if a do {{myvar}} it works. But when a try to pass myvar to a helper, like that {{somehelper ./myvar}}, and console.log it, it returns “null”. Any idea please ?

should be enough, ./ path directive is not needed

1 Like

Replying my own posts as usual… It seems to work only if doing argument="{{somehelper myvar}}". For example : but not <input type=“checkbox” value=“true” {{somehelper myvar}} />
Hopefully that may help someone, because it took me about an hour to understand.

Thank you garrilla. yep, I was just trying everything. But as I explained in my previous post, the problem was that this syntax apparently dont work outside HTML argument.

also why don’t you just keep it simple

       {{#each myarray}}
            {{somehelper @index}}
        {{/each}}

Because actually my real code looks like this:

{{#each step in steps}}
    {{#let stepid=@index}}
    ...
        {{#each event in step.events}}
            {{#let eventid=@index}}
                ...
                <input type=”checkbox” 
                       stepid=”{{stepid}}” 
                       eventid=”{{eventid}}”
                       checked=”{{isChecked stepid eventid}}” />
                 ...
              {{/let}}
        {{/each}}
    {{/let}}
{{/each}}

I was trying the following:

<input type=”checkbox” 
       stepid=”{{stepid}}” 
       eventid=”{{eventid}}”
       {{isChecked stepid eventid}} />