Taurus
Taurus

Reputation: 157

How to force Template.dynamic to re render

I read and tried a lots of solution but i wasn't able to force the Template.dynamic to render again.

In html >>

<body>
    {{> Template.dynamic template=Template}}
</body>

In Meteor.isClient >>

Template.body.helpers({
    'Template': function() {
      return page.template;
    }
  });

I have a function on hashchange event which will change the value of page.template, the event works fine and value will changed every time, but i can't force the Template.dynamic to render again.

page.template is string

I have a function page.getTemplate() > return page.template just to try all options

I'm using the last version of Meteor 1.1.0.2

Upvotes: 0

Views: 184

Answers (2)

Taurus
Taurus

Reputation: 157

Before start , i changed some objects , page.template is now object and page.template.get() will return string, but i don't use it, i pass the template name in Sessions, and this is my page.template.set()

page.template.set = function(name) {
    Session.set('template', name);
  };

Well i found the answer, you need to set a dependency to Sessions, i have done this so far

Template.body.helpers({
    'Template': function() {
      return Session.get('template');
    }
  });

Edited Because of client hack i decided to changed something (you can change the session in console, and i want my router decide to which template should be shown)

page.template.set = function(name) {
  page.template.name = name;
  Session.set('template', name);
};
page.template.get = function() {
  return page.template.name;
};

Template.body.helpers({
  'Template': function() {
     return Session.get('template') ? page.template.get() : page.template.get();
  }
});

Upvotes: 2

Tom Freudenberg
Tom Freudenberg

Reputation: 1367

I am not sure how your app is organized but this should be an easy task. Just use a ReactiveVar to save your active template-name you wish to have selected.

I made a simple MeteorPad for you. Hopefully this is what you are looking for.

http://meteorpad.com/pad/oPhK4KqjiSztRSa9K/SimpleDynamicTemplateSwitch

Cheers Tom

Upvotes: 3

Related Questions