Reputation: 300
how to render the contents of a template .. i can;t pass through this point :/ thanks for your help
example :
<body>
{{> dash}}
</body>
<template name="dash">
<div id="example2" class='example_block'>
<form name = "frm">
<table>
<tr>
<td>Template Name
<td>:
<td><input type="text" name = tname class = "tname">
</frm>
<div class='demo'>
<input type='button' value='Click Here to Create Window' class="btn"/>
</div>
</div>
<div id = "window_block8" style="display:none;"></div>
</template>
<template name="t1">
try1
</template>
<template name="t2">
try2
</template>
//client.js
Template.dash.events({
'click input.btn' : function(){
var temp = document.frm.tname.value ;
Session.set("template" , temp);
$('body').append(Meteor.render(Template[Session.get("currentTemplate")]()));
}
});
some thing like this.. but that code wont work on me
Upvotes: 2
Views: 3483
Reputation: 1837
Meteor.render(Template.try)
returns a document fragment which you can insert into your page with jQuery or vanilla JS.
e.g
Template.dash.aw = function() {
document.body.appendChild(Meteor.render(Template.try));
}
Note that you can use array-style notation if the template name is variable:
document.body.appendChild(Meteor.render(Template[Session.get("currentTemplate")]));
Alternatively, if you only want to return a variable and not an entire template:
Template.try.var = function() {
return 'Hello';
}
Template.dash.aw = function() {
return Template.try.var();
}
// Template.dash.aw = Template.try.var = function() {
// return 'Hello';
// }
The commented function is probably inadequate, since you want some logic in Template.dash.aw
Upvotes: 5