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


#1

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 ?


#2

should be enough, ./ path directive is not needed


#3

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.


#4

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.


#5

also why don’t you just keep it simple

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

#6

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}}

#7

I was trying the following:

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