WeBWorK Main Forum

Removing menus for students in theme

Removing menus for students in theme

by Björn Bergstrand -
Number of replies: 2
I want to hide the left side bar Main menu for a certain class of user. I imagine the best way to do this is to create a custom theme and somehow get it to recognize and hide the menu for these users.

Looking around in the theme math4 (I'm running webwork 2.8) i see that, for instance, the div with id "site-links" is inside a 
<!--#if can="links"--> ... <!--#endif--> statement.

Is this something that enables/disables access? Can I disable a "links"-attribute for a user type in some easy way to achieve this?
In reply to Björn Bergstrand

Re: Removing menus for students in theme

by Alex Jordan -
Maybe you would have to modify ContentGenerator.pm, which would not be a trivial thing to do. At line 581 the links subroutine is defined. You could slap a conditional command at the beginning of this subroutine that made it output an empty string if the user was in that class.

You can see how at line 749, certain links are only present for users that have access to instructor tools. This may help guide you. Or you can also get to the permission level of a user with something like
$db->getPermissionLevel($userName)->permission
In reply to Alex Jordan

Re: Removing menus for students in theme

by Björn Bergstrand -
Thank you for the help!
I ended up adding the function 
sub if_permissionlevel {
        my ($self, $arg) = @_;
        my $r = $self->r;
        my $db = $r->db;
        my $userID = $r->param('user');
        #bail out if not logged in
        return 0 unless $userID;

        if ($db->getPermissionLevel($userID)->permission == $arg) {
                return 1;
        } else {
                return 0;
        }
}

to ContentGenerator.pm, to get e.g. <!--#if permissionlevel="10"--> to work in the template showing content only to (in this case) professors.