Meteor – How to change LayoutTemplate in some expressions? Rail router

My application has multiple layouts to meet different needs, and I want to dynamically select it. For example, depending on GET parameters, or if the user logs in.

< p>How can I do this?

You can actually use this.router in this hook (and possibly other hooks). layout() dynamically changes the layoutTemplate. It is a bit hidden and may change but I can change the layoutTemplate according to whether the user is logged in:

Router.configure({
layoutTemplate: "defaultLayout",
before: function (pause) {
if(!Meteor.user()) {
// render the login template but keep the url in the browser the same
this.router.layout("loginLayout");
this.render('login');

// pause the rest of the before hooks and the action function
pause();
}else{
//Here we have to change the layoutTemplate back to the default
this.router.layout("defaultLayout");
}
}
});

If you have multiple layoutTemplates, this may be a bit complicated, because once the path is no longer paused, it will retain the new layoutTemplate you have set , Unless you change it again.

My application has multiple layouts to meet different needs, and I want to dynamically select it. For example, depending on the GET parameters, or if User login.

How can I do this?

You can actually use this.router.layout() in this hook (and possibly other hooks) to dynamically change the layoutTemplate. It’s a bit hidden, maybe Will change but I can change the layoutTemplate according to whether the user is logged in:

Router.configure({
layoutTemplate: "defaultLayout",
before : function (pause) {
if(!Meteor.user()) {
// render the login template but keep the url in the browser the same
this.router.layout(" loginLayout");
this.render('login');

// pause the rest of the before hooks and the action function
pause();
}else{
//Here we have to change the layoutTemplate back to the default
this.router.layout("defaultLayout");
}
}
} );

If you have multiple layoutTemplates, this may be a bit complicated, because once the path is no longer paused, it will retain the new layoutTemplate you have set, unless you change it again.

< /p>

Leave a Comment

Your email address will not be published.