Canopi Forums
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 08 Jan 2018 03:32 PM by  Dylan Atkinson
Conditional Statements based on DNN role
 0 Replies
Sort:
You are not authorized to post a reply.
Author Messages
Dylan Atkinson
New Member
New Member
Posts:8


--
08 Jan 2018 03:32 PM

    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.

    0
    You are not authorized to post a reply.


    Register for more features

    Register now to post your comments.

    If you Register on the Canopi site you can post questions and comments to the forum.