Multi instances of dynamic template

Hi,
I guess there is no way to define a few instances of dynamic templates? to get something like that?
{{> Template.dynamic id=“a” template=‘one’}}
{{> Template.dynamic id=“c” template=‘other’}}
thanks.

What exactly are you trying to accomplish? You can have as many calls to Template.dynamic as you want, all it does is to include a template based on dynamic parameters (which is pretty much prevented by calling Template.dynamic with a static template=‘one’ value).

For example:

Template.main.helpers({
 isAuth: function() {
  return Meteor.userId() == null ? 'mainAnon' : 'mainAuth';
 }
});
<template name="main">
{{>Template.dynamic template=isAuth}}
</template>

<template name="mainAuth">
 {{currentUser}}
</template>

<template name="mainAnon">
 Please Login
</template>

Yeah, my mistake with using the quotes in the example, but that is clear and I’m using it with fun and pleasure. Let me explain my question.
Assuming in one static template, inside of it, i use a dynamic template, where I switch between templates.
So far so good, but if I have two or more of these kind of pages, would the app know to render the dynamic template into the one which is actually at the view at the moment? that is why I asked if i can call a dynamic template with an id.

Or in other words, should that work:?
< template name=“main” >
{{>Template.dynamic template=one}}
{{>Template.dynamic template=two}}
< /template >

thanks.

You can have multiple calls to Template.dynamic in one template, yes. You can only pass two parameters to Template.dynamic: template and data.

I use something like the following to use a couple of templates that get rendered with different information depending on certain conditions

Template.main.helpers({
 whichTemplateToUse: function(){
  return 'nameOfTemplateToRender';
 },
 theDataPassedToThatTemplate: function() {
  return {
   the: 'data put into the',
   context: 'context of the template rendered'
  }
 }
});
<template name="main">
 {{>Template.dynamic template=whichTemplateToUse data=theDataPassedToThatTemplate}}
</teamplate>

<template name="nameOfTemplateToRender">
 {{the}} {{context}}
</template>
1 Like

Thanks, great explanations, I’ll check it out.