Foren

Role based hyperlinks

Alex Burgazzoli, geändert vor 7 Jahren.

Role based hyperlinks

New Member Beiträge: 4 Beitrittsdatum: 06.01.17 Neueste Beiträge
I am currently creating a theme in which an email icon (fontawesome) is being hard-coded into the header(HTML). The icons consist of the following:
Student Email (hyperlinking to Gmail login)
Staff Email (hyperlinking to O365 login)

I am attempting to do one of two options:
Option A ) Create two separate icons and have only one displayed depending on the users role
Option B ) Create one icon which hyperlinks to the respected email login page depending on the users role

Does anyone have any experience with trying to accomplish such a task? The only current information I can find is based on roles/permissions for custom portlets, and nothing on role based hyperlinks.

I appreciate any information!
thumbnail
Fernando Fernandez, geändert vor 7 Jahren.

RE: Role based hyperlinks

Expert Beiträge: 396 Beitrittsdatum: 22.08.07 Neueste Beiträge
Hi Alex,

Assuming you're changing the theme template, you can do something like this:

#foreach($role in $user.getRoles())
    #if( $role.getName().toUpperCase() == "STUDENT" )
        <a class="..." href="...">....</a>
    #end
#end


This is a velocity example, you might have to change it to freemarker, depending on your theme.

HTH

Fernando
Alex Burgazzoli, geändert vor 7 Jahren.

RE: Role based hyperlinks

New Member Beiträge: 4 Beitrittsdatum: 06.01.17 Neueste Beiträge
Thank you, Fernando!

That worked perfectly.
thumbnail
Fernando Fernandez, geändert vor 7 Jahren.

RE: Role based hyperlinks

Expert Beiträge: 396 Beitrittsdatum: 22.08.07 Neueste Beiträge
I'm glad to have helped. :-)
Alex Burgazzoli, geändert vor 7 Jahren.

RE: Role based hyperlinks

New Member Beiträge: 4 Beitrittsdatum: 06.01.17 Neueste Beiträge
A follow up question you or someone may be able to help with as well.

Say you have multiple roles...
- admin_active
- admin_inactive
- admin_vp

...is it possible to use a generic name that would give access to all roles starting with admin_? such as
#if( $role.getName().toUpperCase() == "ADMIN_%" )

If not, are you able to add multiple roles into the velocity script you recommend?