Iron.DynamicTemplate
Dynamic templates and data contexts for Meteor.
Templates and Helpers
1<body> 2 {{> DynamicTemplate template=getTemplate data=getDataContext}} 3</body> 4 5<template name="MyDynamicTemplate"> 6 My Template Content with Title: {{title}} 7</template>
1if (Meteor.isClient) { 2 UI.body.helpers({ 3 getTemplate: function () { 4 return 'MyDynamicTemplate'; 5 }, 6 7 getDataContext: function () { 8 return { title: 'My Title' }; 9 } 10 }); 11}
Parent Data Contexts
1<body> 2 {{#with someParentData}} 3 {{> DynamicTemplate template=getTemplate}} 4 {{/with}} 5</body>
Default Template Content
1<body> 2 {{#DynamicTemplate template=getTemplate}} 3 No template yet? No problem just render this default content. 4 {{/DynamicTemplate}} 5</body>
From JavaScript
1<body> 2 <div id="optional-container"> 3 </div> 4</body> 5 6<template name="MyDynamicTemplate"> 7 My Template Content with Title: {{title}} 8</template>
1if (Meteor.isClient) { 2 Meteor.startup(function () { 3 // create a new DynamicTemplate instance and optionally set the initial template and data. 4 dynamic = new Iron.DynamicTemplate({ /* template: 'One', data: getData */}); 5 6 // render the component and insert it into the dom defaulting to document.body. 7 dynamic.insert({el: '#optional-container'}); 8 9 // dynamically set the template. 10 dynamic.template('MyDynamicTemplate'); 11 12 // dynamically set the data context. 13 dynamic.data({title: 'My Title'}); 14 15 // clear the dynamic template 16 dynamic.clear(); 17 }); 18}