Show message to users in organization only (or registred)
AnsweredHi team,
I have a list of organizations (100+).
Is there a way to output a temporary notification via template update so only people "assigned to an Organization" or at least only registered users will see the message
Tried to find a condition to use with the <if> statement via https://developer.zendesk.com/apps/docs/help-center-templates/ but no luck.
Thank you
-
Hi
I think, you can do this. I am sharing an example where you can show a message to signed-in users, override that message for users who belong to at least one organization, and further override that for user who belongs to any special organization (from predefined list).
{{#if signed_in}}
<div id="org_message"></div>
<script>
//List of organizations you want to check for
var allowedOrganizations = ["Organization 1", "ORG2"];
function userBelongsToAllowedOrgnizations(allowedOrganizations, userOrganziations) {
var userOrgs = userOrganziations || [];
var found = userOrgs.find(function (userOrg) {
return allowedOrganizations.some(function (ao) {
return ao === userOrg.name
});
});
console.log(found);
return found || false;
}
function userBelongsToAtleastOneOrganization(userOrganziations) {
return userOrganziations.length >= 1;
}
$(document).ready(function () {
var message = "Default message shown to all signed-in users.";
//Use an internal API; if it's gone tomorrow, this can be pulled via API
var userOrganziations = HelpCenter.user.organizations;
//check and show message to user belonging to at least one organization;
if (userBelongsToAtleastOneOrganization(userOrganziations)) {
message = "Yay! You belong to at least one organization.";
}
//check and show message to user belonging to one of organization from allowedOrganizations;
if (userBelongsToAllowedOrgnizations(allowedOrganizations, userOrganziations)) {
//Update the message (above) to something else for user belongs to listed organizations.
message = "Yay! You belong to one of organziations we love most.";
}
$("#org_message").html("<p>" + message + "</p>");
});
</script>
{{else}}
{{!-- Not signed-in; won't show message --}}
{{/if}}Thank you
Team Diziana
Please sign in to leave a comment.
1 Comments