Hi I want to render same template with different data inside a meteor template using Meteor.render. My problem is whenever parent template re-renders it destroys template rendered using Meteor.render. I'm new to meteor and not sure is this the right way to do this thing. Please help. I'm sharing my test code:
test.html
<head>
<title>test</title>
</head>
<body>
{{> test}}
</body>
<template name="test">
<div style="margin: 10px;">
<input type="button" id="render" value="Render">
<input type="button" id="resize" value="Resize">
<div id="placement" style="padding: 10px; background-color: #eee; width: {{width}}px; height: {{height}}px"></div>
</div>
</template>
<template name="temp">
<h1>{{name}}</h1>
</template>
test.js
if(Meteor.isClient){
Template.test.helpers({
height: function() {
return Session.get("size");
},
width: function() {
return Session.get("size");
}
});
Template.test.created = function() {
Session.set("size", 200);
Session.set("name", "Dal Chand");
}
Template.test.events({
'click #render': function(event, template) {
var frag = Meteor.render(function(){
return Template.temp({name: Session.get("name")});
});
var el = document.getElementById('placement');
if(el) el.appendChild(frag);
},
'click #resize': function(event, template) {
var size = Session.get("size");
Session.set("size", (size + 100) % 500 + 300);
}
});
}
So the problem here is when I click on Resize button it removes temp template from the DOM