How can I change the body of template in meteor with a html on another template?

44 Views Asked by At

I'm trying to generate many graph on a template, my first graph is default , I'd like when I click on a zone I generate another graph who exist in a another template. How can I do that ?

I try to return my template with my other grahp.

Template.test.events({'click .zone' : function (e){
  console.log("J'ai cliqué sur le template Test ... on va essayer d'ouvrir une pop up");
  e.preventDefault();
  //$('#animalsModal').modal('show');
  return {template: Template[createGraph]};
}});
1

There are 1 best solutions below

1
On BEST ANSWER

You can use Template.dynamic for this purpose.

//html

<template name="graphDisplayer">
{{> Template.dynamic template=helperToGetDynamicTemplate}}
</template>

//JS

Template.graphDisplayer.onCreated(function(){
  this.templateNameOfGraph = new ReactiveVar('yourDefaultTemplate');
});

Template.graphDisplayer.events({
  'click .zone':function(e,t) {
    t.templateNameOfGraph.set('yourOtherTemplate');
  }
});

Template.graphDisplayer.helpers({
  helperToGetDynamicTemplate:function(){
    return Template.instance().templateNameOfGraph.get();
  }
});