Recherches récentes
Pas de recherche récente
How can I check the user type for the logged in user on Help center Template code?
Avec réponse
Publication le 22 juil. 2021
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 commentaire
Trapta Singh
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
Ifra Saqlain
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.
You can add the content in the header.hbs file and hide that on the user basis like:
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
Groffer Anderson
Thanks Trapta Singh & Ifra Saqlain,
These solutions worked like a charm.
0
Ifra Saqlain
Awesome :)
0
Ashok Gangwar
This link does not exist anymore.
0
Ifra Saqlain
Hi @Ashok Gangwar,
You can share your query. Sometimes it happens that old links don't open.
0
David Bjorgen
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
Support Admin
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
David Bjorgen
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