Best practice for rendering layouts depending on user type


#1

I’m making an application which will have two types of users - providers and customers - and I want to render different layouts for each.

What is considered the best practice for accomplishing this?

Right now I’m using the Iron Router onBeforeAction to check user class and set the correct template, but it seems a little twitchy. While running the application locally at least - the primary layout is shown quickly before the correct layout is rendered.

I should also mention that I’m structuring the application in packages, and will ideally move the the separate user classes into two different packages, which is again separated from the core package.


#2

Could you use a different layoutTemplate depending on the user type?

Using Layouts in Iron Router


#3

Yeah - that’s actually what I’m using. Sorry for not being clear.

I’m asking where I should call layoutTempate. Right now I’m using something like this:

	onBeforeAction: function () {
	if (!Meteor.userId()) {
		this.layout('layout');
		this.next();
	} else if (Meteor.user().is.customer) {
		this.layout('provider');
		this.next();
	} else if (Meteor.user().is.provider) {
		this.layout('client');
		this.next();
	}

EDIT: Ah, I just saw your edit… I’ll try


#4

[haha, i just moved my edit]

alter the router configuration…

Router.configure({
  layoutTemplate: Meteor.user().profile.userType === 'customer' ? 'CustomerLayout' : 'ProviderLayout'
});

#5

What I’m having trouble seeing is how this affects the rendering. I just got the sensation that my current setup - which works - was not ideal.


#6

I think, tho not entirely sure… that in your approach, the default layout is changed in the onbefore, in the approach i’m suggesting the default is set on router config


#7

Yeah! That seems to work much better. Thanks