How can I check the user type for the logged in user on Help center Template code?

Answered


已于 2021年7月22日 发布

Hi, 
I'm looking for a solution where I'll be showing an option on the Zendesk Guide (Help Center) Template on the header only if the user is an Admin or Agent. However, I'm unable to find the right variable in the template code that shows me the user type. 

In the header.hbs code, we have an option to check if the user is signed in or not by variable "signed_in", but we have nothing to check the user type. 

One detail I found on the "user_profile_page.hbs" is that it shows user.admin and user.agent, these variables are not accessible on the header. Is there a solution to pull the user Type? 

Ref Image of code checking if the user is signed in:


1

9

9 条评论

Support Admin, you can always remove the element from the DOM if you're concerned with users gathering data from the HTML.

 

Something like this:

const $element = $(this);

$element.remove(); // Remove element if conditions are not met

0


The only issue with this method is it is sort of a black tape approach. It just hides the content from being displayed rather an inhibit the content from being rendered. In other words, you can still see the original content if you inspect the page's HTML (and theoretically searchable).

 

So do not use this method to hide sensitive or confidential information.

0


The templating API needs to be updated to allow {{user.agent}} on pages other than user_profile_page.hbs. For example, if I want to show data only to agents, it would be nice to have the option to include the following without resorting to Javascript: {{#if user.agent}}Agent stuff here{{/if}}.

0


Hi @Ashok Gangwar,

You can share your query. Sometimes it happens that old links don't open.

0


This link does not exist anymore.

0


Awesome :)

 

0


Thanks Trapta Singh & Ifra Saqlain,
These solutions worked like a charm. 

0


Hi Groffer Anderson,

You can also use the method below:

 you can check the user role using JS:

You can add the user role on the scrip.js file and show/hide any content.

// Show div html based on role
if (HelpCenter.user.role=="anonymous"){
$("div.anonymous").show();
}

if (HelpCenter.user.role=="end_user"){
$("div.end_user").show();
}

if (HelpCenter.user.role=="agent"){
$("div.agent").show();
}

if (HelpCenter.user.role=="manager"){
$("div.manager").show();
}

 

You can add the content in the header.hbs file and hide that on the user basis like:

On header.hbs file

<div class="wrapper"> Content will show only on manager role</div>


On script.js file

$(document).ready(function(){
if (HelpCenter.user.role=="manager"){
$('.wrapper').hide();
}
})

 

the full process that how to use the user role script code so go through the article below:

https://support.zendesk.com/hc/en-us/community/posts/360039994333-How-to-hide-an-article-from-an-anonymous-user-

 

Thanks

 

2


Hi Groffer Anderson,

Zendesk does not provide any variable on the template level to give the user role other than user_profile_page.hbs.

However, you can use JS to achieve this by using window.HelpCenter.user.role

It will give you the current role of the user and on the basis of that, you can show/hide the option.

Let me know if this helps you.

Thanks

1


登录 to leave a comment.

找不到所需的内容?

新建帖子