Let and each programmatically access to the new data


#1

Hello Everybody

I have a question. How are we supossed to access a {{#let newVar=‘hello’}} or a {{#each obj in list}} programatically.
I mean, inside a helper or an event, you can access to the data context, but this variables are not there.

Thanks for your help!


#2

I think they should. Can you please show us a small version of your code?


#3
{{#each person in persons}}
     <span class="name">{{person.name}}</span>
{{/}}
Template.whatever.helpers({
    aHelper: function() {
        //I want to acces to person
        this.person //Doesn't work
        //IT seems like the new variable is not injected in the data context
        var data = Template.currentData();  //Didn't work
        
   }
};

#4

But where do you call the helper?


#5

I dont think there is direct way how to access them.
But as usual there is ugly way, for example

{{#each person in persons}}
     <span class="name">{{person.name}}</span>
    {{#with person}}
        <div class="checker">
    {{/with}}
{{/}}

from helper you can use for example something like this

Blaze.getData(Template.instance().$('.checker'))

And from event handler also, pick it with another DOM query based on template parameter, or use directly event.currentTarget
I did not tested this code exactly, but you know what way I mean