{{> yield}} not working as expected (iron:router)

Hello, when I include {{> yield}} inside a template it somehow alters the behavior of another template (loginButtons disappear from this other template) rather than showing the templates within the template where {{> yield}} is located.

This {{> yield}} is located in a page that is only viewable when a user is logged-in, and the page where the loginButtons disappear is the home page that all users should see when they are not logged in. What I am hoping to achieve is to have users come in to the home page, login and then see the loggedinlayout where different templates will appear based on what users will select from a navbar menu.

This is the code in my router.js file:

Router.map(function(){
// Home
this.route(‘home’, {
path: ‘/’
});

// Logged-in Layout landing
this.route(‘loggedinlayout’,{
layoutTemplate: ‘loggedinlayout’,
path: ‘/loggedinlayout’,
template: ‘welcome’
});

});

var requireLogin = function() {
if (! Meteor.user()) {
this.render(‘home’);
Session.set(‘firstLogin’, true);
} else {
this.render(‘loggedinlayout’);
Session.set(‘firstLogin’, false);
}
};

Router.onBeforeAction(requireLogin);

And this is the code in my html page where {{> yield}} is located:

> <template name="loggedinlayout">
>   
> <head>
> ...
> </head>

> <body id="loggedinlayout">

> {{> navbar}}

> <div class=" container-fluid row" id="loggedinlayout-body">

> {{> yield}}

> </div>

> </body>

> </template>

Any help or advice would be very appreciated. Thanks!

there used to be a line in the Iron Router documentation that body should only contain yield.

<body>
{{>yield}}
</body>

Thanks for your help @jamgold !

I did apply your suggestion of only including {{> yield}} in the body of my loggedin template and the problem of loginButtons not showing up on the home page still existed. However it probably was a step in the right direction. I then added the following ‘router.configure’ at the beginning of my router.js file and it now works as expected. The complete router.js is here for reference:

Router.configure({
layoutTemplate: ‘loggedinlayout’
});

Router.map(function(){
// Home
this.route(‘home’, {
path: ‘/’,
template: ‘home’
});

// Logged-in Layout landing
this.route(‘welcome’,{
path: ‘/welcome’,
template: ‘welcome’
});

});

var requireLogin = function() {
if (! Meteor.user()) {
this.render(‘home’);
Session.set(‘firstLogin’, true);
} else {
this.render(‘welcome’);
Session.set(‘firstLogin’, false);
}
};

Router.onBeforeAction(requireLogin);