Reputation: 43
I have a question about dynamic templates in Meteor. I want to use a template multiple times with other data, but have no idea what I am doing wrong. I have the following template:
<template name="knowyourcompany">
<section>
<header>
<h2>Know your company</h2>
</header>
<p class="question">Q: {{question}}</p>
</section>
</template>
I have the following template helper:
Template.knowyourcompany.helpers({
knowyourcompany1: function(){
return { question: "test" }
}
});
And this is how I include the template
{{> Template.dynamic template="knowyourcompany" data=knowyourcompany1}}
The problem is that I see an empty template. What am I doing wrong?
Upvotes: 1
Views: 237
Reputation: 8345
Template.dynamic
should be used if you want the template to be interchangeable, but in your case you want your data context to be interchangeable, so this is no use case for Template.dynamic
. Instead, use the ordinary {{> templateName myDataContext}}
:
<template name="myMainTemplate">
{{> myTemplate myDataContext}}
</template>
Template.myMainTemplate.helpers({
myDataContext: function(){
return {a: 1, b: 2}
}
})
<template name="myTemplate">
a: {{a}}, b: {{b}}
</template>
Upvotes: 1