Search code examples
meteormeteor-helper

Meteor changing another template reactively


I loaded several templates at startup, Once the page is loaded the user can select several items that will define the content of another template. That's where I am stuck.

How after the call of my method and store the result in my session I can send it to the other Template.

I have looked at Deps.Dependency I sure it is very simple in fact.


Solution

  • Suppose on the first template you had a select element you wanted to save the result of :

    <template name="foodSelect"> <select id="favorite-food"> <option> Taco </option> <option> Burrito </option> </select> </template>

    In the helper for that template you can check for an event on that type of input :

    Template.foodSelect.events({
        "change #favorite-food" : function(event, template) {
            var input = $(event.target).val();
            Session.set('favorite_food', input);
        }
    });
    

    In your other template you can access this by using Session.get('favorite_food') and change the content accordingly.