My meteor app has a base.html file like this:
<head>
<title>MyApp</title>
</head>
<body>
<template name="bodyContent">
{{subContent}}
</template>
</body>
Next, I define three different templates:
<template name="templateA">Some text</template>
<template name="templateB">Bla bla bla</template>
<template name="templateC">Your highscore is {{score}}</template>
How can I make {{subContent}} so it is able to alternate between one of these three templates at runtime?
Something like:
currentTemplateUsed = 'templateB'
Template.bodyContent.subContent = Template[currentTemplateUsed]
But that doesn’t work. Are there other approaches to achieve this functionality?
You should use meteor router, it is able to dynamically change templates. Possible downside is that it can only change one template at a time.
Alternatively, there’s a bit of info on Meteor’s Handlebars:
https://github.com/meteor/meteor/wiki/Handlebars
Basically, you have to use the template as a function, and pass data to it in order for Handlebars to parse it, like this:
Returns
Your highscore is 12