Conditional Statements based on DNN role
NOTE:
These conditional statements will only work with the Canopi/Iwebs Course or Session Browser module.
What problem does this solve?
The conditional statement allows you to direct users to specific areas of the website based on their user role (i.e. Staff Administrators go to an Administrator dashboard, Learners go to a Learner dashboard).
How do I use this feature?
The Canopi/Iwebs Course or Session Browser module uses the 'Apache Velocity Templating Engine' to apply additional data control in the user's view.
The module passes through the $user variable, which includes all the relevant properties passed from the user object. This variable also includes a number of methods which can be called from the object to provide additional functionality. In this scenario, the method used to check the user's DNN roles is: $user.IsInRole("User Role Name").
Any conditional statements use 'blocks' to determine the specified actions between the start and end of the block, should the relevant condition be met. The open and close tags for a block are declared using the '#' symbol before the word. The conditional statement uses the #if, #elseif, #else, and #end key words.
We can put all of this together to provide additional functionality based on the user's role, for example:
Current User: $user.Username $user.Firstname $user.Lastname $user.Email
Is UserInRole Administrators: $user.IsInRole("Administrators")
Is UserInRole Administrators: $user.IsInRole("Registered Users")
#if($user.IsInRole("Administrators"))
Yes you are administrator
#end
Anything else?
If interested, check out the documentation for the 'Apache Velocity Templating Engine' for conditional statements.