I have 3 people, each with unique answer to the same question.
1 template shows the name and question. Another different template holds the answer. (4 total templates. 1 for names/question, 3 other - 1 for each unique answer).
<template name="people">
{{#each profile }}
<h2>{{ name }}</h2>
<p>{{ question }}</p>
<p>{{> answer }}</p>
{{/each }}
</template>
I want to set up a helper, so that when each profile loop is running, I can insert the correct named template (instead of {{> answer }}, 3 distinct templates identified by their name {{> nameAnswers }}, aka {{> fooAnswers }}.
Tried this, which displays all 3, in each profile, instead of 1 per profile.
<template name="people">
{{#each profile }}
<h2>{{ name }}</h2>
<p>{{ question }}</p>
{{#if nameHelper=Fred }}
{{> fredAnswers }}
{{/if }}
{{#if nameHelper=Ringo }}
{{> ringoAnswers }}
{{/if }}
{{#if nameHelper=Jackson }}
{{> jacksonAnswers }}
{{/if }}
{{/each }}
</template>
Note: the {{> nameAnswers }} templates are already defined as static html, need to insert them is all.
you can to do this...
Using Blaze
https://github.com/meteor/meteor/wiki/Using-Blaze
<template name="people">
{{#each profile }}
<h2>{{ name }}</h2>
<p>{{ question }}</p>
{{#if isName Fred }}
{{> fredAnswers }}
{{/if }}
{{#if isName Ringo }}
{{> ringoAnswers }}
{{/if }}
{{#if isName Jackson }}
{{> jacksonAnswers }}
{{/if }}
{{/each }}
</template>
Template.people.helpers({
isName:function(name){
return //true or false;
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With