Access User role in dev portal smart docs

prasadwalke
Participant II

I want to access the role of a user in dev portal smart docs HTML template and based on that role I want to show particular div eg if a user is anonymous then one div should be executed and if a user is authenticated then other div should be executed.

eg : if (role=="anonymous"){
	div 1 to be display
	}
     if (role == "authenticated"){
	div 2 to be display 
      	}

So how can I access the role of use in HTML or javascript ??

Any help would be appreciated

0 4 178
4 REPLIES 4

ElangoD
Participant III
  • Each of the SmartDoc MEthod is called a node. If u want to hide Div based on user role in ".tpl.php" file
    global $user;
if (array_key_exists('Machine Name of the Role', $user->roles)) {
   // Logic 
}
else (array_key_exists('Machine Name of the Role', $user->roles)) {
  //Else Logic
} 
  • If you want to show some Smartdoc to Restricted users and hide from unauthenticated and also registered users You can use Taxonomy Access Control Drupal Module.which allow map users role to terms.

Thanks a lot Elango
But is there any way to access this user variable in javascript or HTML directly ??

and where can I get this tpl.php file

Go through the link give an overview to work with js &JQuery,

1. You need to use Drupal js setting.

In your .module file add


global $user; $setting = array('name_of_the_module'=> array('user_role' => $user->roles) drupal_add_js($setting, 'setting')

Then inside Js file, need to attach behaviour.attach

    Drupal.behaviour.name_of_the_module = {
 attach: function (context, settings) {
          var user_role = settings.name_of_the_module.user_role;
  }}

2. Tpl.php file in sites/all/themes/<themeName>/templates/node.tpl.php, Before this APigee comes with "apigee starter kit" theme, can extend this create sub-theme and do all required changes for your design.

Thanks a lot Elango