Meteor には 3 つの単純なテンプレートがあり、サーバーには任意の名前の組み合わせを持つコレクションがあります。コレクションに含まれる名前に基づいて、これらのテンプレートを動的にレンダリングできるようにしたいと考えています。
現在、クライアントを使用してコレクションをサブスクライブし、テンプレート関数を介して名前にアクセスすることで、これを達成しようとしています。残念ながら、名前に対して">"を実行しようとすると、Meteor はその値が指すテンプレートではなく、変数名をレンダリングしようとします。
したがって、テンプレート1 、テンプレート2 、およびテンプレート3 でhtml をレンダリングする代わりに、出力は単にページ上の名前「テンプレート 1 テンプレート 2 テンプレート 3」になります。
これが私が使用しているコードです。Meteor.render を手動で実行しなくても問題を解決できる方法があることを願っています。
サーバーjs:
TemplatesToRender = new Meteor.Collection("templatesToRender");
TemplatesToRender.insert({templateName: "template3"});
TemplatesToRender.insert({templateName: "template2"});
クライアント html:
<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>