I have a collection of questions and want to iterate through them based on a next button. I can update a ReactiveVar or session variable named ‘counter’ but when I pass the variable to the Template helper, I get an error that the variable is undefined.
Thanks or your interest!
JS Code:
Session.setDefault(‘counter’, 0);
Template.contestQuestion.helpers({
counter: function () {
return Session.get(‘counter’);
},
question: function () {
return Questions.find({order: counter});
}
});
Template.contestQuestion.events({
‘click .next’: function () {
// increment the counter when button is clicked
Session.set(‘counter’, Session.get(‘counter’) + 1);
OK. it is working now. I had initialized variable with session.setdefault so it wasn’t updating. Switched to session.set.
I’m going to try to refactor with template scope.