Restrict Custom block at home page based on user group
You can put restriction over custom block by hiding it based on user group.
Original post can be find here
In order to hide custom block from home page just do the following
1. Go to Theme editor > JS
2. Add the below js code
/* JS */
$(document.ready(function() {
//HelpCenter is an undocumented object provided by Zendesk.
//Please use it on your own riks.
if( typeof HelpCenter.user != 'undefined'
&& (HelpCenter.user.role != 'manager'
&& HelpCenter.user.role != 'agent'
&& HelpCenter.user.role != 'end-user')) {
$('li.view-restrict').remove();
}
});
3. Go to HTMl > Home-page and add the class "view-restrict" to the <li> tag of the block to be restrict
<li class="view-restrict">
<a href="YOUR-CATEGORY-URL">
<img src="image-url" alt="image-alt" />
</a>
</li>
4. Save the changes
Note: If you want your end user to preview the block when login, just remove end user from the js
&& HelpCenter.user.role != 'end-user'
Hope that helps everyone.
Enjoy!
-
Thanks, Diziana! You know we always love your tips!
-
Hi there,
When 'lurking' around in the source code, I found this message, right above the declaration of the HelpCenter.user object:
We also use this object's values to restrict content based on users (e.g., only show feature x to authenticated users).
Is this note still accurate? In other words, should we be worried about the HelpCenter.user object being removed in the future (and thus breaking our current Help Center's functionality)?
The above code is from an inline script included in the html of https://[brand].zendesk.com/hc/en-us
-
Hi Joe!
The note is accurate. It doesn't necessarily mean that anything is going to change, but we can't promise that changes won't happen as Zendesk continues to grow and evolve. We don't want your stuff to break in the event that happens because we won't be able to help you fix your customizations, which is why we put the note there.
Please let me know if you have other questions, or need any further clarification!
-
Thanks, Jessie! Totally makes sense. We'll use this cautiously and won't blame you if it ever changes :)
-
Thank you! Been looking for a way to do this a couple of days now!!! Cheers!
I changed the JS from <li> to <p> and it looks like it works as well!
-
@Joe: It's good idea not to use any undocumented stuff, we try not to. We are working to find a way to replace code which uses HelpCenter object anywhere.
-
@Tobias: We are glad that it helped you.
@Jennifer: Where is our goody for the tip? ;-)
-
Hey Diziana,
I sent you something via email a few months back, but it looks like it was never redeemed. Email me at community@zendesk.com and I'll give you the link again! You've definitely earned it. :)
-
Hi,
HelpCenter is an undocumented object, i know that the HelpCenter.user.tags exists, do you know if HelpCenter.organization.tags exists, and if there is a hidden link where i can get all the arguments that i can use, like the place holder ? it would be nice
-
Hey Jean-Michel WEISS -
You can type HelpCenter into your browser console on a Zendesk Help Center page and see the results for yourself. I just did it now while typing out my comment and I do see that my organizations and the organizations tags are listed. So you should be able to get the data as well.
-
Not working on my side, Jennifer Rowe, an idea ? anyway thanks for the advice
-
Hello Jean-Michel WEISS -- organizations are at the user level of the HelpCenter object -- it looks like you may be checking at a higher level (HelpCenter.organization.tags):
-
on my side, there is no HelpCenter.organization, only HelpCenter.user.organization, any idea ? thanks again
-
You're right. There is no HelpCenter.organization value. The organization information is tied to the signed-in user. If you need the overall set of Organizations for an account, you'll want to call the GET /api/v2/organizations.json API.
-
Any reason the instructions provided by the original poster would not work today? (It was written 5 years ago). I tried the instructions but it doesn't seem to work correctly. Simply placing the JS code in my JS file breaks the formatting of my home page and I can't scroll the entire page properly. Anyone know what the best current way would be to restrict a custom block on the home page by user group?
Please sign in to leave a comment.
15 Comments