How can I link to different sub-templates from different templates in Meteor?
I have 5 templates. Two templates are called one, which in turn calls the other two depending on which template it was called from.
I want to do the following:
<template name="Template1">
<!-- show his things -->
{{BaseTemplate SubTemplate1}}
</template>
<template name="Template2">
<!-- show his things -->
{{BaseTemplate SubTemplate2}}
</template>
<template name="BaseTemplate">
{{#each xpto}}
<!-- show base things -->
{{BaseTemplate {{CallSubTemplateGiven}} }}
{{/each}}
</template>
<template name="SubTemplate1">
<!-- show few things -->
</template>
<template name="SubTemplate2">
<!-- show other things -->
</template>
Is there a way to do this? Couldn't figure out how to do this using RegisterHelper.
+3
source to share
1 answer
You should be able to do this by passing an additional template as an argument to the base template and then using template.dynamic to render the correct one.
<template name="Template1">
{{> BaseTemplate subtemplate=SubTemplate1 }}
</template>
<template name="Template2">
{{> BaseTemplate subtemplate=SubTemplate2 }}
</template>
<template name="BaseTemplate">
{{#each xpto}}
{{> Template.dynamic template=../subtemplate }}
{{/each}}
</template>
<template name="SubTemplate1">
</template>
<template name="SubTemplate2">
</template>
+1
source to share