Jason Chen
Jason Chen

Reputation: 2577

Meteor: activating other templates through click?

By default I set one of my templates to return false. What I would like to do is have a click event that changes my previous template to return true. My code is as follows:

Template.mypage.helpers({
pagefunction(){ return false;}
});

Template.mypage.events({
'click #randomdiv': function(){
pagefunction(){ return true; }
} 
});

The command doesn't work, but demonstrates hopefully what I am trying to achieve. I would like pagefunction to return true when I click on a div that is within the same template.

Meanwhile, my HTML looks something along the lines of:

<template name="mypage">
    {{#if pagefunction}}
    {{> atemplate}}
    {{/if}}
</template>

Upvotes: 0

Views: 27

Answers (2)

李振纲
李振纲

Reputation: 382

try do this to solve session can't get,type the code at the beginning

var PAGE_KEY='page_key';

Session.setDefault(PAGE_KEY,false);

Upvotes: 1

Michel Floyd
Michel Floyd

Reputation: 20227

You need to turn that event into state. The most common way of doing this is using a Session variable.

Template.mypage.helpers({
  pagefunction(){ return Session.get('myState'); }
});

Template.mypage.events({
  'click #randomdiv': function(){
    Session.set('myState',true);
  } 
});

Upvotes: 1

Related Questions