Ever wondered to show the same page but different Menu Options to different users based on their roles? Well, it’s now possible.
In this example, there are 4 Types of User’s & each one is assigned with a Badge. Badges are Upper Management, Admin Staff, Teacher & Student. Members of Upper Management have access to ‘All Pages’ while others have access to few ones only. There is no need to show them other pages if they don’t have access. Hence, four menu’s are created named ‘allmenu’ , ‘adminmenu’ , ‘teachermenu’ & ‘studentmenu’
Note:-
‘allmenu’ is shown by default while rest are ‘hiddenbydefault’.
All Menus are inside the same grid & stretched to max area of same grid.
Code is to be entered in Site Code.
Menu Section is set as Site Master Part.
import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(function () { check();});
wixUsers.onLogin( (user) => {check();} );
function check () {
wixData.query("Members/Badges")
.hasSome("members", wixUsers.currentUser.id)
.find()
.then((results) => {
let a = results.items[0].title;
if (a === 'Student') {
$w('#studentmenu').show();
$w('#allmenu').hide();
} else if (a === 'Teacher') {
$w('#teachermenu').show();
$w('#allmenu').hide();
} else if (a === 'Admin Staff') {
$w('#adminmenu').show();
$w('#allmenu').hide();
} else {
$w('#allmenu').show();
}
})
}