Session variable not working in Template


#1

Hi Experts… I am novice user and trying to show different templates inside a template on clicking on a button. Setting and retrieving values from session is working fine. When loading the form I have set a display vairiable false and clicking a button I set the same session variable false. The value changes and it shows up properly in the getsetter in chrome browser. But, the following code always goes through the else part, never executes the if part, regardless of the session variable. Can you help…

Using iron router. 

route.js
Router.route('page01', {
  path: '/page01',
  template: 'page01',
  onBeforeAction: function(){
    Session.set('newDeal', false);
    this.next();
  }
});



page01.js
=======
Template.page01.events({
    'click .new-deal': () => {
    Session.set('newDeal', true);
  }

page01.html
==========
<template name='page01'>
Welcome to my page!!
<button class="new-deal">Click for New</button>	

    {{#if .Session.get 'newDeal'}}
        {{ >NewPage}}
    {{else}}
        My content goes here
    {{/if}}

</template>

NewPage.html
=============
<template name='NewPage'>
        Here you can enter new page details... 
       <button class="close-deal"><i class="fa fa-close"></i></button>	
</template>


NewPage.js
============
Template.NewPage.events({
	'click .fa-close': function() {
		Session.set('newDeal', false);
	}
});

What is going wrong here. I can see the values changes from false to true and back to false upon clicking the new button and close button. Meteortoys getSetter shows appropriates values, but the template never honor those values and the if condition never goes to if section, it always executes the else section in the page01.html template.


#2

Where is the template helper for .Session.get?


#3

Thank you jamgold. I have added a helper method, and it worked! I thought .Session.get is available from Session package.

If that helps anyone else, I have added this helper method.


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

and changed the Template like below…

   {{#if isNewDeal}}
        {{ >NewPage}}
    {{else}}
        My content goes here
    {{/if}}