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
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 }
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
User | Count |
---|---|
7 | |
2 | |
2 | |
2 | |
1 |