I have three simple templates in Meteor and a collection on the server with any combination of their names. I want to be able to visualize these templates dynamically based on which of their names is in the collection.
I am currently trying to accomplish this using a client to subscribe to a collection and access names through a template function. Unfortunately, if I try to run a ">" in the names, Meteor will try to display the variable name instead of the template pointed to by its value.
Therefore, instead of displaying html in templates1, template2 and template3, the output is simply their names on the page: "template1 template2 template3".
Here is the code I used, I hope there is a way to solve my problem without having to run Meteor.render manually.
Js server:
TemplatesToRender = new Meteor.Collection("templatesToRender"); TemplatesToRender.insert({templateName: "template3"}); TemplatesToRender.insert({templateName: "template2"});
Html client:
<body> {{#each templatesToRender}} {{> templateName}} // meteor trying to render a template // called "templateName" instead of the // variable inside templateName. {{/each}} </body> <template name="template1"> <span>Template 1</span> </template> <template name="template2"> <span>Template 2</span> </template> <template name="template3"> <span>Template 3</span> </template>
J yang
source share