user3277570
user3277570

Reputation:

Meteor: Spacebars not updating on session-value change

I have this html-File in Meteor

{{#if thevalue}}
    {{> one}}
{{else}}
    {{> two}}
{{/if}}

and this helper

'thevalue': Session.get('thevalue') //returns true or false

My problem is that when the Session-Value changes, the if/else-Bracktes from Spacebars do not change with it. I thought Session-Values are reactive...but maybe I have some sort of misconception how this works.

Upvotes: 1

Views: 200

Answers (2)

danSiebes
danSiebes

Reputation: 384

Session is reactive and helper is a reactive computation. The problem may be the format of your helper which should be like this:

  thevalue: function(){
      return Session.get('thevalue');
    }

The problem could simply be that you are putting 'thevalue' in quotes and turning it in to a string where I believe it needs to run as a function.

Keep in mind if your 'thevalue' is 0 then your spacebars will return {{> two}}.

Upvotes: 0

PhilippSpo
PhilippSpo

Reputation: 789

Try to write your helper as a function like so

'thevalue': function () {
  return Session.get('thevalue');
}

See the docs here for more.

Upvotes: 0

Related Questions