Dynamic Template

I’ve been trying to figure out whats going on with this dynamic template for a good deal of time and can’t seem to make any progress. I asked a question on stack and no one has been able to give me a solution. I have the following template within which I would like to display one of four other templates.

<template name = "selectFrame">
    <div class = "container">
        <div class = "frameCarousel">
            {{> Template.dynamic template=active data=this}}
        </div>
    </div>
</template>

Active is a template helper that determines which template should be shown.

Template.selectFrame.helpers({
active: function() {
	return Session.get('board');
}
});

Can anyone offer any insight into why my templates aren’t reacting correctly?

What is your Session variable? Is it a string? Or is it a template object?

The way I have personally done this in the past is like below:

<template name = "selectFrame">
    <div class = "container">
        <div class = "frameCarousel">
            {{> getTemplate data=this}}
        </div>
    </div>
</template>
Template.selectFrame.helpers({
    getTemplate: function() {
	return Template[Session.get('board')]; // Where Session.get('board') returns a string that accesses the Template object
    }
});

Make sure your active helper returns the name of an existing template

The session variable is set from the id of a button on a previous wizard page. I tried your edit and it still only allows the default template to be rendered. As ‘board’ changes, which I checked and it does, no new template is rendered when advancing to the wizard step where the selectFrame template is called

I’ve checked and double checked the names, they are correct. Each template displays properly but only when they are set as the SessionDefault value

Do you have a repo I could take a look at?

I am using Template.dynamic and it works as advertised (example). Using nested dynamic templates I found out is a sure way to crash your app/browser, however.

1 Like

Your code works for me: http://meteorpad.com/pad/ndiE7ayeE7gT6n58t/ maybe the problem is somewhere else?

So i think the problem is that the button isn’t within the same template. I’m working on creating a wizard with jQuery Steps. So the button that sets the variable is within the template for step 1 and the dynamic template is in the template for step 2. I want the template in step 2 to be dynamic because the choice from step 1 determines which template gets loaded in step 2. Any ideas?